a. Write an application that instantiates a JFrame that contains a JButton. Disable the JButton after the user clicks it.
b. Modify the JFrameDisableButton program so that the JButton is not disabled until the user has clicked atleast 8 times. At that point, display a JLabel that indicates "That's enough!".
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JFrameDisableButton extends JFrame implements ActionListener
{
JButton button = new JButton("Enabled");
JLabel label = new JLabel("");
public JFrameDisableButton()
{
super("Enabled-Disabled");
setLayout(new FlowLayout());
add(button);
add(label);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
final int LIMIT = 8;
int i;
int times = 0;
for(i = 0;i<8;i++)
{
if(source == button)
{
++times;
if(times == 8)
{
button.setEnabled(false);
}
}
}
}
public static void main(String[] args)
{
JFrameDisableButton y = new JFrameDisableButton();
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 150;
y.setSize(FRAME_WIDTH, FRAME_HEIGHT);
y.setVisible(true);
y.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
I just can't answer the problem and if you don't mind, can you tell me if I answered letter a correctly when it comes to instantiation of JFrame? Thank you.

New Topic/Question
Reply



MultiQuote






|