我的 JFrame 没有添加 JTabbedPane,我不知道崩溃是否是我的 eclipse 的某种错误。没有语法错误或任何对我来说似乎是错误的东西。其他人可以尝试运行它并查看它是否有效吗?代码已经准备好运行。提前致谢
public class MainScreen extends JFrame implements ActionListener {
JMenuBar bar;
JMenu file, register;
JMenuItem close, search;
ImageIcon logo= new ImageIcon("rsc/img/sh-logo.jpg");
ImageIcon worldIcon= new ImageIcon("rsc/img/world-icon.png");
JLabel lbImage1;
JTabbedPane tabbedPane = new JTabbedPane();
JPanel entrance = new JPanel();
public MainScreen()
{
JFrame mainFrame = new JFrame();
lbImage1= new JLabel(logo, JLabel.CENTER);
entrance.add(lbImage1);
tabbedPane.addTab("SHST", worldIcon, entrance);
mainFrame.add( tabbedPane, BorderLayout.CENTER);
bar= new JMenuBar();
file= new JMenu("File");
register= new JMenu("Search");
close= new JMenuItem("Close");
close.addActionListener(this);
search= new JMenuItem("Request Query");
search.addActionListener(this);
//Keyboard Shortcut
register.setMnemonic(KeyEvent.VK_S);
file.setMnemonic(KeyEvent.VK_F);
search.setMnemonic(KeyEvent.VK_R);
//mainFrame Setup
bar.add(file);
bar.add(register);
file.add(close);
register.add(search);
mainFrame.add(bar);
mainFrame.setExtendedState(getExtendedState() | mainFrame.MAXIMIZED_BOTH); // Maximized Window or setSize(getMaximumSize());
mainFrame.setTitle("SHST");
mainFrame.setJMenuBar(bar);
mainFrame.setDefaultCloseOperation(0);
mainFrame.setVisible(true);
WindowListener J=new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
};
addWindowListener(J);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==close){
System.exit(0);
}
}
public static void main (String[] args){
MainScreen m= new MainScreen();
}
}