import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; /* * JButtonExercise.java * * Created on October 8, 2005, 12:18 PM * * COP 3337 */ /** * * @author Bill Kraynek */ public class JButtonExercise { int button12Count = 0; int button22Count = 0; int button32Count = 0; JButton button12; JButton button22; JButton button32; /** Creates a new instance of JButtonExercise */ public JButtonExercise() { JFrame theFrame = new JFrame("JButtons Exercise"); // Add code to set theFrame's size and Layout // Add code to construct a Type1 button panel JLabel label1 = new JLabel("Type 1 Buttons"); JButton button11 = new JButton("Reset Type 2 Buttons"); JButton button21 = new JButton("Results of Type 2 Buttons"); // Add code to add label1 and the 2 buttons to the Type1 button panel button11.addActionListener(new Button11Action()); button21.addActionListener(new Button21Action()); // Add code to put the Type1 button panel into a JScrollPane and add to theFrame JLabel label2 = new JLabel("Type 2 Buttons can be pressed only twice"); // Add code to construct a label2 panel, add label2 to the label2 panel and // add the label2 panel to theFrame // Add code to construct a Type2 button panel button12 = new JButton("Button1 Type2"); button22 = new JButton("Button2 Type2"); button32 = new JButton("Button3 Type2"); // Add code to add the 3 buttons to the Type2 button panel // Add code to addActionLister classes you constructed below to the Type 2 buttons // Add code to put the Type2 button panel into a JScrollPane and add to theFrame theFrame.setVisible(true); } class Button11Action implements ActionListener { public void actionPerformed(ActionEvent e) { // Add code to enable all Type2 buttons and reset counts to 0 } } class Button21Action implements ActionListener { public void actionPerformed(ActionEvent e) { // Add code to display Type2 button counts ia a JOptionPane window } } // Add code to construct 3 classes that implements ActionListener, one for // each of the Type 2 buttons. In each class add code to increment the // corresponding Type2 button count and disable it if count >= 2 /** * @param args the command line arguments */ public static void main(String[] args) { new JButtonExercise(); } }