View Single Post
  #1 (permalink)  
Old 07-04-2007, 06:35 AM
Albert Albert is offline
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
Help with 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. 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?

Code:
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
Thanks

Albert
Reply With Quote
Sponsored Links