Question: Programming Practice Access the following Java source file: StopLight.java using this link. You should see a blank drawing ready for you as the artist to

Programming Practice

Access the following Java source file: StopLight.java using this link. You should see a blank drawing ready for you as the artist to begin your wo

Enter the Java code to draw a stoplight.

StopLight.java

// Delta College - CST 183 - Klingler // This application draws a stoplight import java.awt.*; import javax.swing.*; public class StopLight extends JPanel { public void paintComponent( Graphics g ) { // Set up drawing context super.paintComponent( g ); // Enter drawing code to create stoplight here } public static void main( String args[] ) { // Instantiate drawing panel StopLight drawPanel = new StopLight(); // Instantiate application object JFrame application = new JFrame(); // Add drawing panel to application application.add(drawPanel); // Set application attributes application.setSize( 300,500 ); application.setVisible( true ); application.setTitle( "My Stoplight" ); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } } 

Expert Answer

Programming Practice Access the following Java source file: StopLight.java using this link.SrkKhan answered this

Was this answer helpful?

0

0

768 answers

PLEASE FIND THE CODE BELOW:

package graphichal;

// Delta College - CST 183 - Klingler // This application draws a stoplight

import java.awt.*; import javax.swing.*;

public class StopLight extends JPanel { public void paintComponent( Graphics g ) { // Set up drawing context super.paintComponent( g ); //draw base g.fillRect(200, 700, 300,30); //draw pipe g.fillRect(350, 500,30,200); //draw board for light g.fillRect(287, 250,150,400); //draw head g.fillArc(260, 200, 200, 200, 0, 180); //put lights g.setColor(Color.RED); g.fillOval(315, 300, 100, 100); g.setColor(Color.ORANGE); g.fillOval(315, 410, 100, 100); g.setColor(Color.GREEN); g.fillOval(315, 520, 100, 100); // Enter drawing code to create stoplight here }

public static void main( String args[] ) { // Instantiate drawing panel StopLight drawPanel = new StopLight(); // Instantiate application object JFrame application = new JFrame(); // Add drawing panel to application application.add(drawPanel);

// Set application attributes application.setSize( 500,500 ); application.setVisible( true ); application.setTitle( "My Stoplight" ); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } }

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!