5.11 (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals
This section demonstrates drawing rectangles and ovals, using the Graphics methods drawRect and drawOval, respectively. These methods are demonstrated in Fig. 5.27.
Click here to view code image
1 // Fig. 5.27: Shapes.java 2 // Drawing a cascade of shapes based on the user’s choice. 3 import java.awt.Graphics; 4 import javax.swing.JPanel; 5
6 public class Shapes extends JPanel 7 { 8 private int choice; // user's choice of which shape to draw 9
10 // constructor sets the user's choice11 public Shapes(int userChoice)12 {13 choice = userChoice;14 }15
16 // draws a cascade of shapes starting from the top-left corner17 ...