B
Bernd1983
Gast
hi, hab ein Problem ein Rechteck zu zeichnen
und swing:
Ich bekomme eine NullPointerexception.Wieso? Wieso wird kein Rechteck gezeichnet?
grüsse
Code:
class Quad extends Figure {
int x,y,w,h;
Quad(int x,int y, int w, int h){
super(x);
this.y=y;
this.w=w;
this.h=h;
}
public void paintMe(Graphics g){
g.drawRect(x,y,w,h);
}
}
und swing:
Code:
class SwingDemo extends JFrame implements ActionListener{
int a,b,c,d;
Quad x;
Graphics y;
JButton green;
SwingDemo(){
getContentPane().setLayout(new FlowLayout());
green=new JButton("rechteck?");
green.addActionListener(this);
getContentPane().add(green);
x=new Quad(15,25,7,16);
}
public void actionPerformed(ActionEvent a){
x.paintMe(y);
}
}
public class DesignPattern {
public static void main(String [] args){
SwingDemo a=new SwingDemo();
a.setSize(150, 100);
a.setVisible( true );
}
}
Ich bekomme eine NullPointerexception.Wieso? Wieso wird kein Rechteck gezeichnet?
grüsse