public class DrawTest {
public static void main(String[] args) {
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.show();
}
}
/**
* A frame that contians a panel with drawings
*/
class DrawFrame extends JFrame{
public static final int DEFAULT_WIDTH = 400;
public static final int DEFAULT_HEIGHT = 400;
public DrawFrame(){
setTitle( "DrawTest" );
setSize( DEFAULT_WIDTH, DEFAULT_HEIGHT );
// add panel to frame
DrawPanel panel = new DrawPanel();
Container contentPane = getContentPane();
contentPane.add( panel );
}
}
/**
* A panel that display rectangle and ellipses.
*/
class DrawPanel extends JPanel{
public void paintComponent( Graphics g ){
super.paintComponent( g );
Graphics2D g2 = (Graphics2D)g;