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 gain experience in

- using objects
- constructing objects and supplying initial values
- using member functions and the dot notation
- modifying and querying the state of an object through its member functions
- writing simple graphics programs containing points, lines, circles and text.
- selecting appropriate coordinate systems
- processing user input and mouse clicks in graphics programs
- developing test cases that validate the correctness of your programs

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?

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

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

Draw each circle in a *different color* of your choice.

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

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

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 Intersect.java 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.

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:

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