View Single Post
  #3 (permalink)  
Old 07-04-2007, 05:44 AM
Eric Eric is offline
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
What you want to paint on, is not the JFrame, but on its contentPane.

This is more or less the way I always do it, by using JPanels:
Code:
import javax.swing.JFrame; class{ main{ //create JFrame JFrame frame = new JFrame ("A JFrame"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //create instance of drawing class //i guess you could do it on init().. Design d = new Design(); //add contentPane to frame //add drawings to contentPane frame.getContentPane().add(d); frame.pack(); frame.setVisible(true); } }
Code:
import javax.swing.JPanel; Design class extends JPanel{ public Design(){ //constructor //add initial values ... //set panel color and size setBackground (Color.gray); setPreferredSize (new Dimension(600,600)); } ...stuff public void paint(Graphics g) { //drawings go here super.paint(g); ....stuff } ...stuff }
Greetings

Eric
Reply With Quote