Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS 171G – Fall 2012 
Lab 6 
Graphics 2 
 
 
25 points possible.   Submit ShapeApplet.java on Canvas. 
 
Materials related to this assignment can be found in the 
"Graphics" Module on Canvas. 
 
Review:  A Java applet is a program designed to be embedded in a web page.  An applet needs a web page 
(html file) in order to run. 
Java has 13 built-in colors.  You'll be using all 13 colors in your program for this assignment.
1. Color.white 
2. Color.black 
3. Color.red 
4. Color.green 
5. Color.blue 
6. Color.magenta 
7. Color.cyan 
8. Color.yellow 
9. Color.gray 
10. Color.lightGray 
11. Color.darkGray 
12. Color.orange 
13. Color.pink 
 
Create ShapeApplet.java 
 Using JGrasp, write a Java applet.   
 
The applet should do the following: 
 
a. Draw 7 filled rectangles, each 60 pixels wide x 60 pixels high. The colors are black, white, red, green, 
blue, yellow and magenta.   
 
b. Draw a black, unfilled rectangle (a border only) around the white rectangle.  
 
c. Draw 6 filled ovals, each 60 pixels wide x 60 pixels high.  The colors are cyan, light gray, gray, dark 
gray, pink and orange.  The ovals should just barely touch the adjacent rectangles.  Use the appropriate 
x and y coordinates so that your applet looks like this:   
 
 
Programmer Name 
d. Draw your name at the left, as shown. Use black for the color.  Remember that in Java, the way to 
“draw” text on the screen is by using the drawString method.  Here’s an example: 
  g.drawString( "Hello!", 20, 50 ); 
This statement will display the word  Hello! on the screen. The x-coordinate is 20 and the y-coordinate 
is 50.  The point (20, 50) will be at the bottom, left corner of the letter H. 
The word is drawn in whatever color has been set.   
 At the top of the ShapeApplet.java program include comments with your name, CS 171G, and a brief 
description of what the program does.  
 
 Save the program with the name ShapeApplet.java.   Compile the program.  Fix any syntax errors.  
Compile again.  Repeat until no syntax errors. 
 
Remember that the compiler is going to create a bytecode file for you.   The name of the bytecode file 
will be ShapeApplet.class. 
 
The bytecode file is "portable".  It can be moved from one type of computer to another without any 
compatibility issues. 
 
 
 Display the applet with appletviewer.  The appletviewer window may not be big enough to display your 
entire business card.  If it's too small, just drag the bottom-right corner of the window to make it big 
enough. 
 
 If it doesn't look the way you want it to, make changes, save, compile, view again...repeat. 
 
*** CLOSE ALL FILES BEFORE EXITING FROM JGRASP *** 
 
 
Submit ShapeApplet.java on Canvas.