我需要幫助這個代碼,我試圖做一個簡單的cookie點擊器類型的遊戲,我已經完成了大部分代碼,但由於某種原因,當我嘗試添加JLabel的框架,它創造了一個錯誤,我希望你們中的一個人能夠幫助我,我對Java相當陌生,感謝您的幫助!我想要一個JLabel出現後按JButton
//Variables
static int clicked = 0;
private FlowLayout layout;
private Container container;
public static void main(String [] args) {
//Declaring the buttons, panels, etc...
JButton button = new JButton("Click");
JPanel panel = new JPanel();
panel.add(button);
final JFrame frame = new JFrame("Button Pressed");
frame.setSize(400, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.add(panel);
//Action Listener Code
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Execute when button is pressed
clicked++;
System.out.println("Button pressed " + clicked + " times!");
}
}
}
非常感謝的人! – Mrsoldier3201
不客氣。 – Braj
@ Mrsoldier3201你應該接受答案,如果它真的幫助你:) –