Computer Programming I - Solutions for Assignment 3 | CS 121, Assignments of Computer Science

Material Type: Assignment; Class: Computer Programming I; Subject: Computer Science; University: Pace University-New York; Term: Fall 1999;

Typology: Assignments

Pre 2010

Uploaded on 08/09/2009

koofers-user-hp0-1
koofers-user-hp0-1 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 121
Assignment 3
Due: October 11, 1999
Create a Java applet that will draw three circles similar to those on a traffic light. Their colors
should be red, yellow (orange actually looks better) and green. Position them on the applet in the
order that they would be for a traffic light. Run the applet from an html file like the one below.
<HTML>
<HEAD>
<TITLE>Lights</TITLE>
</HEAD>
<BODY>
<H1>Lights</H1>
<APPLET CODE="Lights.class" WIDTH=300 HEIGHT=300></APPLET>
</BODY>
</HTML>
Your applet should have the following form:
// An applet with a class that draws a few circles that look like a traffic light.
import java.awt.*;
import java.applet.Applet;
public class Lights extends Applet
{
private circle redCircle, yellowCircle, greenCircle;
public void init ()
{
redCircle = new circle ();
yellowCircle = new circle ();
greenCircle = new circle ();
} // method init
public void paint (Graphics g)
{
// Fill in the statements here that would draw the circles.
} // method paint
} // class shapes
// A class that defines a circle.
class circle
{
public void displayCircle (Graphics g, Color c, int xPos, int yPos, int diameter)
{
// Fill in the statements here that would set the color and draw the circle.
} // method displayCircle
} // class circle

Partial preview of the text

Download Computer Programming I - Solutions for Assignment 3 | CS 121 and more Assignments Computer Science in PDF only on Docsity!

Computer Science 121 Assignment 3 Due: October 11, 1999 Create a Java applet that will draw three circles similar to those on a traffic light. Their colors should be red, yellow (orange actually looks better) and green. Position them on the applet in the order that they would be for a traffic light. Run the applet from an html file like the one below.

Lights

Lights

Your applet should have the following form: // An applet with a class that draws a few circles that look like a traffic light. import java.awt.*; import java.applet.Applet; public class Lights extends Applet { private circle redCircle, yellowCircle, greenCircle; public void init () { redCircle = new circle (); yellowCircle = new circle (); greenCircle = new circle (); } // method init public void paint (Graphics g) { // Fill in the statements here that would draw the circles. } // method paint } // class shapes // A class that defines a circle. class circle { public void displayCircle (Graphics g, Color c, int xPos, int yPos, int diameter) { // Fill in the statements here that would set the color and draw the circle. } // method displayCircle } // class circle