shirleymck
07-02-2007, 09:08 PM
In the Paint method of a JFrame I can call a method like drawRect( ) and it will work. But when I try to call a class method for drawing, it won't work. It creates the window but doesn't draw anything in it. Here is a simple example. It uses a class, Design, that just uses drawRect and drawOval. An applet can use the Design class and its methods just fine. Why can't the JFrame do the same?
import java.awt.*;
import javax.swing.*;
public class DrawTest extends JFrame {
Design d;
public DrawTest( ) {
super( "Drawing Test" );
setSize(100, 100 );
setVisible( true );
}
public void init( ) {
d = new Design( );
}
public void paint( Graphics g ) {
super.paint( g );
d.draw( g );
}
public static void main( String args[] ) {
DrawTest application = new DrawTest( );
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end of main
} // end of DrawTest
import java.awt.*;
import javax.swing.*;
public class DrawTest extends JFrame {
Design d;
public DrawTest( ) {
super( "Drawing Test" );
setSize(100, 100 );
setVisible( true );
}
public void init( ) {
d = new Design( );
}
public void paint( Graphics g ) {
super.paint( g );
d.draw( g );
}
public static void main( String args[] ) {
DrawTest application = new DrawTest( );
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end of main
} // end of DrawTest