gpt4 book ai didi

java - 出现编译错误列表,然后在Eclipse中迅速消失

转载 作者:行者123 更新时间:2023-12-02 11:02:47 25 4
gpt4 key购买 nike

因此,我正在创建一个摆动GUI。我期望在运行代码后看到的窗口出现,并且一切运行正常,除了在我的窗口 pop 之前控制台上突然出现了许多错误,然后错误消失的程度与出现的错误一样。我无法确定这些“错误”是什么,因为它们的出现时间不到一秒钟左右。我也不知道是否应该担心,因为我的代码可以正常工作。

如果有人需要进行诊断,我将在此处添加代码。

我的JPanel类:(注意:稍后将填充ActionListener和ItemListener方法)

public class BoardPanel extends JPanel implements ActionListener, ItemListener{


private JMenu m2difficultyMenu, m1boardSizeMenu;
private JMenuBar menuBar;
private JRadioButtonMenuItem m1r1, m1r2, m2r1, m2r2, m2r3;
private JCheckBox cb1;
private JButton startButton;
private ButtonGroup m1Group, m2Group;
private JLabel label;
private JPanel p1, p2, p3;

public BoardPanel(){
setLayout(new BorderLayout());
p1=new JPanel();
//p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
p2=new JPanel();
//p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
p3=new JPanel();
p3.setBorder(BorderFactory.createEmptyBorder(100, 0, 0, 0));
p1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 100));
p2.setBorder(BorderFactory.createEmptyBorder(0, 100, 0, 0));

//creating menus
m2difficultyMenu=new JMenu("Stufe");
m1boardSizeMenu=new JMenu("Groesse");

//creating menu bar
menuBar=new JMenuBar();

//creating buttons, radio buttons, and check boxes
label=new JLabel("Choose your settings then hit play. Good luck!");
m1r1=new JRadioButtonMenuItem("3x3");
m1r2=new JRadioButtonMenuItem("4x4");
m2r1=new JRadioButtonMenuItem("leicht");
m2r2=new JRadioButtonMenuItem("mittel");
m2r3=new JRadioButtonMenuItem("Unschlagbar");
cb1=new JCheckBox("Hinweise");
startButton=new JButton("Spielen!");
startButton.setBackground(Color.RED);
startButton.setForeground(Color.white);

//setting borders
label.setBorder(BorderFactory.createEmptyBorder(200,125,100,0));
//p1.add(Box.createHorizontalStrut(100));
//p2.add(Box.createHorizontalStrut(100));

//creating button groups
m1Group=new ButtonGroup();
m2Group=new ButtonGroup();

//Assigning buttons to groups
m1Group.add(m1r1);
m1Group.add(m1r2);
m2Group.add(m2r1);
m2Group.add(m2r2);
m2Group.add(m2r3);

//Adding menus to the menu bar
menuBar.add(m2difficultyMenu);
menuBar.add(m1boardSizeMenu);
menuBar.add(cb1);
//menuBar.add(Box.createHorizontalGlue());

//Adding buttons to difficulty menu
m2difficultyMenu.add(m2r1);
m2difficultyMenu.add(m2r2);
m2difficultyMenu.add(m2r3);

//Adding buttons to size menu
m1boardSizeMenu.add(m1r1);
m1boardSizeMenu.add(m1r2);

//Adding components to panels
add(p1, BorderLayout.LINE_START);
add(p2, BorderLayout.LINE_END);
add(p3, BorderLayout.PAGE_END);
add(label, BorderLayout.PAGE_START);
add(startButton, BorderLayout.CENTER);

startButton.setFont(new Font("Arial", 1, 40));
setPreferredSize(new Dimension(500,500));
}


/**
*
* @return Returns the menu bar for use in the JFrame class
*/
public JMenuBar getBar(){
return menuBar;
}
@Override
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub

}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub

}

}

JFrame类:
public class BoardFrame extends JFrame {
private BoardPanel panel;
public BoardFrame() {
panel=new BoardPanel();
setJMenuBar(panel.getBar());
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setContentPane(panel);
setTitle("TicTacToe");
setResizable(false);
pack();
setVisible(true);
}

public static void main(String[] args) {
// TODO Auto-generated method stub
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
new BoardFrame();
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
}
}
});
}
}

这是我所看到的,这是预期的:

enter image description here

最佳答案

从命令行运行代码并在该处看不到任何错误消息后,我重新启动了Eclipse,就可以了。因此,只需要重新启动Eclipse。

关于java - 出现编译错误列表,然后在Eclipse中迅速消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31891695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com