Question
Hey! Can anyone complete this Java programming assignment? I am a beginner programmer so please keep the code as simple as possible! You are going
Hey! Can anyone complete this Java programming assignment? I am a beginner programmer so please keep the code as simple as possible! You are going to need access to a JButtonPractice.java file which I have provided a copy/paste of below the images. Your help is extremelly appreciated!
Here is a copy of the code in the JButtonPractice.java that you need in order to complete the project. If you need any further information feel free to let me know!
/* JButtonPractice, Programming Activity 1 Anderson, Franceschi */
import java.awt.*; import javax.swing.*; //import java.awt.event.*;
public class JButtonPractice extends JFrame { public static final long serialVersionUID = 1234L; Container contents; // GUI components private JButton open; private JButton close; private Circuit circuit;
private static JButtonPractice app; private boolean firstTime = true;
public JButtonPractice( ) { super( "Choose your activity" ); contents = getContentPane( ); contents.setLayout( new FlowLayout( ) );
circuit = new Circuit( );
open = new JButton( "OPEN" ); contents.add( open ); close = new JButton( "CLOSE" ); contents.add( close );
// ***** 1. Student code starts here // declare and instantiate the button handler // and register it on the buttons
// end of task 1
setSize( 500, 375 ); setVisible( true ); }
// ***** 2. Student code restarts here // Code a private class to implement the correct Listener // and its required method // To open the switch, call the open method with the statement // open( ); // To close the switch, call the close method with the statement // close( ); // The last statement of the method should be // animate( );
// end of task 2
public void open( ) { circuit.open( ); }
public void close( ) { circuit.close( ); }
// private void animate( ) // { // try // { // repaint( ); // Thread.sleep( 200 ); // } // catch ( InterruptedException e ) // { // System.out.println( "IE Exception " + e.getMessage( ) ); // System.out.println( e.toString( ) ); // } // }
public void paint( Graphics g ) { if ( firstTime ) firstTime = false; super.paint( g ); circuit.draw( g ); }
public static void main( String [] args ) { app = new JButtonPractice( ); app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); }
12.8 Programming Activity 1: Working with Buttons In this activity, you will work with two JButtons that control one electri- cal switch. Specifically, you will write the code to perform the following operations: 1. If the user clicks on the "OPEN" button, open the switch. 2. If the user clicks on the "CLOSE"' button, close the switch. The framework for this Program ming Activity will animate your code so its accuracy. Figure 12.10 and Figure 12.1l show the that you can check application after the user has clicked on the button labeled "OPEN" and the button labeled "CLOSE", respectively Figure 12.10 Choose your activity User Clicked on "OPEN" OPENCLOSE Power source Light bulb Switch
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started