can't getGraphics from JPanel
Hi,
I want to get the graphics context from a JPanel so I can draw on it. In the example below,theStage ends up null, causing a null pointer exception - where am I going wrong?
class winextends JFrame{
Container c;
win(){
stage stage =new stage();
c = getContentPane();
c.add(stage);
setSize(400,400);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
class stageextends JPanel{
stage(){
Graphics2D theStage = (Graphics2D)getGraphics();
theStage.drawLine(0,0,100,100);
}
}
}
big thanks for any help,
Des

