当我在大学网络服务器上的html标签中运行我的代码时,我很难从主JApplet类调用其他JApplet: 我有一个设计为JApplet的库数据库应用程序,当我在eclipse上运行并按下顾客功能按钮或管理功能按钮时,来自顾客类和管理类的JApplet工作正常,但当我在大学网络服务器上运行它并尝试在html标签中运行它并尝试按下patron功能或管理功能按钮没有任何反应没有弹出JFrame来自任何这些类的JApplet出现,我正在使用这样的html类标签:
<center>
<applet code="library/MainMenu.class" height="400" width="500">
</applet>
</center>
任何建议我应该添加或消除什么来运行项目或我做错了什么,我有点困惑。谢谢 下面是我到目前为止的所有代码:
package library;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import library.PatronFunctionsMenu;
public class MainMenu extends JApplet implements ActionListener {
private JFrame mainFrame;
private JLabel mainMenulbl;
private JButton patronFunctionBtn, administrativeFunctionBtn,
quitBtn;
private JPanel mainPanel;
PatronFunctionsMenu patronJApplet;
AdministrativeFunctionsMenu administrativeJApplet;
public MainMenu() {
mainFrame = new JFrame();
mainPanel = new JPanel();
mainMenulbl = new JLabel("MAIN MENU", SwingConstants.CENTER);
mainMenulbl.setFont(new Font("Serif", Font.PLAIN, 18));
patronFunctionBtn = new JButton("1- Patron functions (ask for card number " +
"then show submenu) " );
administrativeFunctionBtn = new JButton("2- Administrative functions");
quitBtn = new JButton("3- Quit");
patronJApplet = new PatronFunctionsMenu();
administrativeJApplet = new AdministrativeFunctionsMenu();
}
public void init() {
mainFrame.setSize(600,400);
mainFrame.setLayout(new BorderLayout());
mainFrame.setTitle("MAIN MENU");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.add(mainPanel);
mainPanel.setLayout(new GridLayout(10,1));
//adding a jlabel
//patronFunctionBtn.setSize(80, 291);
mainPanel.add(mainMenulbl);
//adding jbuttons
mainPanel.add(patronFunctionBtn);
mainPanel.add(administrativeFunctionBtn);
mainPanel.add(quitBtn);
mainFrame.setVisible(true);
patronFunctionBtn.addActionListener(this);
administrativeFunctionBtn.addActionListener(this);
quitBtn.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == patronFunctionBtn)
{
JTextField textArea = new JTextField(15);
int okCxl = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(this),
textArea, "Enter Library Card Number and click ok!", JOptionPane.OK_CANCEL_OPTION);
if (okCxl == JOptionPane.OK_OPTION) {
String text = textArea.getText();
patronJApplet.start();
patronJApplet.init();
//JFrame patron = new JFrame();
//patron.findComponentAt(getLocation());
getContentPane().add(patronJApplet.getContentPane());
//setSize(800, 500); // not sure about this. Usually better to call pack();
setVisible(true);
}
}
if (e.getSource() == administrativeFunctionBtn) {
administrativeJApplet.start();
administrativeJApplet.init();
getContentPane().add(administrativeJApplet.getContentPane());
setVisible(true);
}
if (e.getSource() == quitBtn)
{
System.exit(0);
}
}
}
//PatronFunctionsMenu class
package library;
import java.applet.Applet;
import java.awt.*;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class PatronFunctionsMenu extends JApplet
implements ActionListener {
private JFrame patronFrame;
private JPanel patronPanel;
private JLabel patronLabel;
private JButton bookCheckout;
private JButton bookReturn;
private JButton payFine;
private JButton printLoanedBooksList;
private JButton quit;
public PatronFunctionsMenu() {
patronFrame = new JFrame();
patronPanel = new JPanel();
patronLabel = new JLabel("PATRON FUNCTIONS MENU ", SwingConstants.CENTER);
patronLabel.setFont(new Font("Serif", Font.PLAIN, 18));
bookCheckout = new JButton("(1)- Book Checkout");
bookReturn = new JButton("(2)- Book Return");
payFine = new JButton("(3)- Pay Fine");
printLoanedBooksList = new JButton("(4)- Print Loaned Books List");
quit = new JButton("(5)- Quit");
}
public void init(){
/*
// don't do this, just call pack() later
//mainJFrame.setSize(600,400);
mainJFrame.setLayout(new BorderLayout());
mainJFrame.setTitle("Travel Agent System");
mainJFrame.setBackground(Color.BLUE);
mainJFrame.pack();
// should be last.
mainJFrame.setVisible(true);*/
patronFrame.setSize(500, 400);
patronFrame.setLayout(new BorderLayout());
patronFrame.setTitle("PATRON FUNCTIONS MENU");
patronFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
patronFrame.add(patronPanel);
patronPanel.setLayout(new GridLayout(10,1));
patronPanel.add(patronLabel, SwingConstants.CENTER);
patronPanel.add(bookCheckout);
patronPanel.add(bookReturn);
patronPanel.add(bookReturn);
patronPanel.add(payFine);
patronPanel.add(printLoanedBooksList);
patronPanel.add(quit);
//patronFrame.pack();
patronFrame.setVisible(true);
quit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
patronFrame.setVisible(false);
//PatronFunctionsMenu applet = new PatronFunctionsMenu();
}
});
patronPanel.add(quit);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
//AdministrativeFunctionsMenu class
package library;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class AdministrativeFunctionsMenu extends JApplet
implements ActionListener {
private JFrame administrativeFrame;
private JPanel administrativePanel;
private JLabel administrativeLabel;
private JButton addBookButton;
private JButton updateBookHoldingButton;
private JButton searchBookButton;
private JButton newPatronButton;
private JButton printBranchInfoButton;
private JButton quitAdministrativeButton;
public AdministrativeFunctionsMenu() {
administrativeFrame = new JFrame();
administrativePanel = new JPanel();
administrativeLabel = new JLabel("ADMINISTRATIVE FUNCTIONS MENU ", SwingConstants.CENTER);
administrativeLabel.setFont(new Font("Serif", Font.PLAIN, 18));
addBookButton = new JButton("(1)- Add a book");
updateBookHoldingButton = new JButton("(2)- Update book holdings");
searchBookButton =new JButton("(3)- Search book");
newPatronButton = new JButton("(4)- New patron(add patron)");
printBranchInfoButton = new JButton("(5) Print branch information");
quitAdministrativeButton = new JButton("(6)- Quit");
}
public void init() {
administrativeFrame.setSize(500, 400);
administrativeFrame.setLayout(new BorderLayout());
administrativeFrame.setTitle("ADMINISTRATIVE FUNCTIONS MENU");
administrativeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
administrativeFrame.add(administrativePanel);
administrativePanel.setLayout(new GridLayout(10,1));
administrativePanel.add(administrativeLabel);
administrativePanel.add(addBookButton);
administrativePanel.add(updateBookHoldingButton);
administrativePanel.add(searchBookButton);
administrativePanel.add(newPatronButton);
administrativePanel.add(printBranchInfoButton);
administrativePanel.add(quitAdministrativeButton);
administrativeFrame.setVisible(true);
quitAdministrativeButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == quitAdministrativeButton) {
administrativeFrame.setVisible(false);
}
}
}