Computing Concepts with Java Essentials
Laboratory Notebook
Chapter 4 - Applets and Graphics

Your name:
Your email address:
Your student ID number:

Once this form has been customized for your institution, you can use this button to send your lab work. Be sure to read the instructions before starting your work.

Lab Objectives

To gain experience in

Graphics Structures

P1. Lines

Write an applet that uses three Line2D.Double objects to draw a triangle, like this:


Anytine you write an applet, you need to provide both a Java program and an HTML file. What HTML file are you supplying to run this applet?

P2. Rectangles and Ellipses

Use Rectangle2D.Double and Ellipse2D.Double objects to draw an automobile like this :

Line drawing Automobile

P3. Colors

Generate five circles with radius 20, 40, 60, 80, and 100, all tangent at a common point, like this.

Line drawing tangent circles

Draw each circle in a different color of your choice.

P4. Getting Input from an Option Pane

Write a program that 1) prompts for the user's name and 2) draws the name inside a rectangle.

P5. Comparing Visual and Numerical Information

Write a program that draws three lines, as in the following figure.

Plot line on Cartesian plane

When the program starts, it should ask the user for a value v. Then it draws the line joining the origin (0,0) with the point (v, 200):

Line2D.Double line1 = new Line2D.Double(0, 0, v, 200); 

Note that the equation of this line is

y = x * 200 / v

The second (horizontal) line has the equation

x = 100

You can obtain it as

Line2D.Double line2 = new Line2D.Double(100, 0, 100, getWidth());

The third (vertical) line has equation

y = 100

Finally, mark the intersection points with small circles and print their coordinate values. To compute the intersection points, you need to solve two sets of equations. This set gives you the first intersection point:

y = x * 200 / v

x = 100

This set gives you the second intersection point:

y = x * 200 / v

y = 100

Tip: Start with the program from the textbook. You need to change the equations, but the code for drawing and labeling the intersection points is helpful.

Run the program with a value of x = 160. What intersection points does your program produce?

Verify the computation by calculating the values by hand. Show your work here.

P6. Choosing a Coordinate System (Advanced)

Given a coordinate system where the upper lefthand corner is (0,0) and the lower righthand corner is (3,3), write a graphics program to draw a stopsign like this:

irregular stopsign

Don't forget to send your answers when you're finished.