// File: TestAwt9.java (Module 9) // // Author: Rahul Simha // Created: October 13, 1998 // // Solving the inset problem - v2. import java.awt.*; class NewFrame extends Frame { int width, height; int originx, originy; int draw_width, draw_height; // Constructors. public NewFrame (int width, int height) { // Set the title and other parameters. this.setTitle ("Inset problem"); this.setResizable (true); this.setBackground (Color.cyan); this.setSize (width, height); this.width = width; this.height = height; // Show the frame. this.setVisible (true); // Compute insets. // Call getInsets AFTER calling setVisible() Insets I = this.getInsets (); originx = 0+I.left; originy = 0+I.top; draw_width = width - (I.right + 1); draw_height = height - (I.bottom + 1); } // No-parameter constructor - use a default size. public NewFrame () { this (500, 300); } // Override paint(): public void paint (Graphics g) { // Draw circles of diameter 100 at each corner. // Topleft at 0,0: g.drawOval (originx, originy, 100,100); // Topleft at (0, height-100): g.drawOval (originx, draw_height-100, 100,100); // Topleft at (width-100, 0): g.drawOval (draw_width-100, originy, 100,100); // Topleft at (width-100, width-100): g.drawOval (draw_width-100, draw_height-100, 100,100); } } public class TestAwt9 { public static void main (String[] argv) { NewFrame nf = new NewFrame (300, 300); } }