drawing in a JFrame
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.It gives a NullPointerException at DrawTest.paint at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source). I find it puzzling that it mentions RepaintManager since it won't even draw for the first time. It also mentions EventDispatchThread.
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

