I want to put multiple JPanel on my JFrame.
public class Rect extends JFrame{
public Rect () {
gui();
}
class DrawPane extends JPanel{
private int x=0;
public DrawPane(int x){
this.x=x;
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.fillRect(x, 20, 100, 200);
}
}
private void gui() {
setSize(600, 400);
addWindowListener(new MyWindowListener());
getContentPane().add(new DrawPane(20)); //first object
getContentPane().add(new DrawPane(100)); //second object
setVisible(true);
}
public static void main(String[] args) {
new Rect ();
}
}
I am creating two DrawPane-Objects, but only the second appears. What could be the problem? It should'nt be a problem to insert more than one JPanel on a JFrame.