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:
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);
}
}
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