C++ Lab Exercises – Week 3



Computer Science 221

Lab Exercises

Week 9

Objective: Learn to draw and paint shapes using the Java Graphics class; use Java switch statements to create a menu-driven program.

Preparation: Read sections 5.1-5.6 of Wu. For each lab exercise,

• write out a flow chart showing the decision(s) to be made

• from your flow chart, write pseudo code switch statements that make the decision(s). Do not write complete Java programs, just focus on the switch statements.

Make two copies of your flow charts and pseudo code. Turn in one copy at the beginning of lab and keep the other copy to use during lab. This written preparatory work counts for half of your lab grade. Late work is not accepted.

Exercise:

(Demonstrate your solution to the instructor, lab assistant, or tutor by Thursday.)

Write a Java program that behaves as follows:

• The user is shown a menu (or series of menus) in the console window to choose a figure to be drawn or painted (line, rectangle, filled rectangle, 3D rectangle, filled 3D rectangle, round rectangle, filled round rectangle, oval, filled oval, arc, or filled arc).

• After the user chooses the figure, he/she is prompted to enter the values for the parameters, associated with this figure in the console window.

• The requested figure is drawn on a JFrame object and a message dialog box displays the name of the figure (e.g. "filled 3D rectangle")

Challenge: Draw the chosen figure 10 times with gradually changed location and size.

If the drawing does not appear on the screen, before drawing include next delay statement:

try { Thread.sleep(200) ; }catch(Exception e) {}

introduces delay of 200 ms. If you still may not see the drawing, increase the delay (e.g. 2000).

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download