我正在尝试为我的班级编写一个程序,该程序在单击后Computer Science
禁用 a 。但是,它在我单击一次后立即禁用。我仍然不确定我做错了什么。JButton
8 times
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JFrameDisableButton extends JFrame
{
public static void main(String[] args)
{
JFrameDisableButton window = new JFrameDisableButton();
window.setVisible(true);
}
final int WIDTH = 150;
final int HEIGHT = 150;
private Font bigFont = new Font("Arial", Font.BOLD, 16);
private JButton disableButton = new JButton("Disable");
private Container pane = getContentPane();
private JLabel annoyed;
public JFrameDisableButton()
{
super("Disable Frame");
setSize(WIDTH,HEIGHT);
setLayout(new FlowLayout());
pane.add(disableButton);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DisableButtonListener disableListener = new DisableButtonListener();
disableButton.addActionListener(disableListener);
}
private class DisableButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent click)
{
if(actionPerformed(ActionEvent (click = 8)))
{
disableButton.setEnabled(false);
}
else
{
disableButton.setEnabled(true);
annoyed = new JLabel("That's enough!");
pane.add(annoyed);
annoyed.setFont(bigFont);
}
}
}
}