Java Reference
In-Depth Information
The window is 220 pixels wide and 150 pixels tall. The background is yellow. There are two blue ovals of size 40
40
pixels. They are 80 pixels apart, and the left oval's top-left corner is located at position (50, 25). There is a red square
whose top two corners exactly intersect the centers of the two ovals. Lastly, there is a black horizontal line through
the center of the square.
×
2. Modify your program from the previous exercise to draw the figure by a method called drawFigure . The method
should accept three parameters: the Graphics g of the DrawingPanel on which to draw, and a pair of x/y coordi-
nates specifying the location of the top-left corner of the figure. Use the following heading for your method:
public static void drawFigure(Graphics g, int x, int y)
Set your DrawingPanel 's size to 450
150 pixels, and use your drawFigure method to place two figures on it, as
shown in Figure 3G.20. One figure should be at position (50, 25) and the other should be at position (250, 45).
×
Figure 3G.20
3.
Write a program with a static method called showDesign that uses the DrawingPanel to draw Figure 3G.21.
Figure 3G.21
The window is 200 pixels wide and 200 pixels tall. The background is white and the foreground is black. There are
20 pixels between each of the four rectangles, and the rectangles are concentric (their centers are at the same point).
Use a loop to draw the repeated rectangles.
Search WWH ::




Custom Search