// File: TestAwt6.java (Module 9) // // Author: Rahul Simha // Created: October 13, 1998 // // Geometric figures: an improved version. import java.awt.*; class NewFrame extends Frame { // Constructors. public NewFrame (int width, int height) { // Set the title and other parameters. this.setTitle ("Some Geometric Figures"); this.setResizable (true); this.setBackground (Color.cyan); this.setSize (width, height); // Show the frame. this.setVisible (true); } // No-parameter constructor - use a default size. public NewFrame () { this (500, 300); } // Override paint(): public void paint (Graphics g) { // Draw a Square: g.drawRect (50,50,50,50); g.drawString ("Square", 50, 115); // Circle: g.drawOval (200,50,50,50); g.drawString ("Circle", 200, 115); // Rounded rectangle: g.drawRoundRect (350,50,75,50,20,20); g.drawString ("Rectangle", 350, 115); // Draw a line across the middle: g.drawLine (0,150,500,150); // Now draw some filled shapes: // Square: g.fillRect (50,200,50,50); g.drawString ("Square", 50, 265); // Circle: g.fillOval (200,200,50,50); g.drawString ("Circle", 200, 265); // Rounded rectangle: g.fillRoundRect (350,200,75,50,20,20); g.drawString ("Rectangle", 350, 265); } } public class TestAwt6 { public static void main (String[] argv) { NewFrame nf = new NewFrame (500, 300); } }