I got 2 classes:
- 1st. makes a frame (JFrame) and adds a panel (JPanel) on it
- second one makes the panel and draws a rectangle on it (at least i thought it would)
this is the first class
class Frame {
JFrame frame;
Panel panel;
void draw() {
frame = new JFrame ("qwertz");
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setSize(300,200);
panel = new Panel();
panel.setLayout(null);
panel.paint();
frame.add(panel);
}}
and the second
class Panel extends JPanel {
void paint() {
Graphics g = getGraphics();
g.drawRect(50,50,90,70);
}}
when i call the draw() method from the first class it throws this exception at me:
java.lang.NullPointerException
at Panel.paint(Panel.java:8) (( g.drawRect(50,50,90,70); ))
at Frame.draw(Frame.java:15) (( panel.paint(); ))