Question: Java How to Program Early Objects 10th edition. Part 1 Code the GUI example found on pages 496 and 497. You will need two files

Java How to Program Early Objects 10th edition. Part 1 Code the GUI example found on pages 496 and 497. You will need two files (ButtonFrame.java, ButonTest.java). The file for ButtonFrame will also contain the ButtonHandler class. Part 2 Create a class called HighLowGame to play the high low game. The class should have the following methods: HighLowGame(int numberOfNumbers), String guess(int numberGuessed) should return Correct after X guesses or Wrong, Guess Higher, or Wrong, Guess Lower. Part 3 In create a GUI app that uses this class to play the game. Use a JTextField to collect the user guess. Code for GUI example follows: import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class ButtonFrame extends JFrame{ private final JButton plainJButton; // button with just text private final JButton fancyJButton; // button with icons //ButtonFrame adds JButtons to JFrame public ButtonFrame(){ super("Testing Buttons"); setLayout(new FlowLayout()); plainJButton = new JButton("Plain Button");//button with text add(plainJButton);//add plainJButton to JFrame Icon bug1 = new ImageIcon(getClass().getResource("bug1.gif")); Icon bug2 = new ImageIcon(getClass().getResource("bug2.gif")); fancyJButton = new JButton("Fancy Button", bug1);//set image fancyJButton.setRolloverIcon(bug2);//set rollover image add(fancyJButton); //addfancyJButton to JFrame //create new ButtonHandler for button event handling ButtonHandler handler = new ButtonHandler(); fancyJButton.addActionListener(handler); plainJButton.addActionListener(handler); } //inner class for button event handling private class ButtonHandler implements ActionListener{ //handle button event @Override public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(ButtonFrame.this, String.format("You pressed: %s", event.getActionCommand())); } } }//end class ButtonFrame import javax.swing.JFrame; //Fig 12.16: ButtonTest.java //Testing ButtonFrame public class ButtonTest { public static void main(String[] args) { ButtonFrame buttonFrame = new ButtonFrame(); buttonFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buttonFrame.setSize(375, 210); buttonFrame.setVisible(true); } }

//Command buttons and action events import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane;

public class ButtonFrame extends JFrame{

private final JButton plainJButton; // button with just text private final JButton fancyJButton; // button with icons //ButtonFrame adds JButtons to JFrame public ButtonFrame(){ super("Testing Buttons"); setLayout(new FlowLayout()); plainJButton = new JButton("Plain Button");//button with text add(plainJButton);//add plainJButton to JFrame Icon bug1 = new ImageIcon(getClass().getResource("bug1.gif")); Icon bug2 = new ImageIcon(getClass().getResource("bug2.gif")); fancyJButton = new JButton("Fancy Button", bug1);//set image fancyJButton.setRolloverIcon(bug2);//set rollOver image add(fancyJButton); //addfancyJButton to JFrame //create new ButtonHandler for button event handling ButtonHandler handler = new ButtonHandler(); fancyJButton.addActionListener(handler); plainJButton.addActionListener(handler); } //inner class for button event handling private class ButtonHandler implements ActionListener{ //handle button event @Override public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(ButtonFrame.this, String.format("You pressed: %s", event.getActionCommand())); } } }//end class ButtonFrame

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!