I have problem displaying drawing on JPanel. I created three class which linked to each other as the following. I was wondering why this code, doesn't display my drawing.
c.add(pDraw);
pDraw.add(draw);
1) MAIN
public class mainPage {
public static void main(String[]args){
JFrame appFrame = new Frame();
appFrame.setVisible(true);
appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
2) JFRAME
public class Frame extends JFrame implements ActionListener{
private drawingBoard draw;
public Frame (){
draw = new drawingBoard(); //generate pattern
GridBagLayout m = new GridBagLayout();
Container c = (Container)getContentPane();
c.setLayout (m);
GridBagConstraints con;
.......
JPanel pDraw = new JPanel();
pDraw.setPreferredSize(new Dimension(500,500));
.....
c.add(pDraw);
pDraw.add(draw); // Call other class for drawing
.....
setResizable(false);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
3) JPANEL
public class drawingBoard extends JPanel {
.....
public void paint(Graphics g) {
......
}
}