Sun Java Solaris Communities My SDN Account Join SDN
 
Code sample

Code Samples from the Java Developers Almanac 2000

 

Code Samples Index

These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms

The Quintessential Drawing Program

This example creates a frame and draws an oval within the frame.

 import java.awt.*;
 import javax.swing.*;
     
 class BasicDraw extends JComponent {
   public void paint(Graphics g) {
     Graphics2D g2d = (Graphics2D)g;
     
     g2d.drawOval(0, 0, getSize().width-1, 
       getSize().height-1);
   }
     
   public static void main(String[] args) {
     JFrame frame = new JFrame();
     frame.getContentPane().add(new BasicDraw());
     int frameWidth = 300;
     int frameHeight = 300;
     frame.setSize(frameWidth, frameHeight);
     frame.setVisible(true);
   }
 }
 

Examplets provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan.
Order this book from Amazon