coshamak
April 7th, 2011, 04:57 PM
public class Main
{
public static void main(String[] args)
{
JFrame frame = new JFrame("2DGRAPHICS_EXAMPLE");
Paintexample paint=new Paintexample();
paint.init();
frame.add(paint);
frame.setResizable(false);
frame.setSize(new Dimension(1024, 650));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true);
}
}
this is the main and i call to paint.init().....
but the applet shotdown.
way?
this is the paint class:
public class Paintexample extends JApplet
{
private Graphics g;
JPanel panel;
public void init()
{
this.setLayout(new BorderLayout());
this.panel=new JPanel();
this.panel.setPreferredSize(new Dimension(1024,500));
this.add(panel);
g=this.panel.getGraphics();
Paint(g);
}
public void Paint(Graphics g2)
{
g2=this.panel.getGraphics();
g2.setColor(Color.black);
g2.drawRect(50, 50, 400, 400);
}
}
the eclipse write this messege:
Exception in thread "main" java.lang.NullPointerException
at Paintexample.Paint(Paintexample.java:28)
at Paintexample.init(Paintexample.java:23)
at Main.main(Main.java:9)
{
public static void main(String[] args)
{
JFrame frame = new JFrame("2DGRAPHICS_EXAMPLE");
Paintexample paint=new Paintexample();
paint.init();
frame.add(paint);
frame.setResizable(false);
frame.setSize(new Dimension(1024, 650));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true);
}
}
this is the main and i call to paint.init().....
but the applet shotdown.
way?
this is the paint class:
public class Paintexample extends JApplet
{
private Graphics g;
JPanel panel;
public void init()
{
this.setLayout(new BorderLayout());
this.panel=new JPanel();
this.panel.setPreferredSize(new Dimension(1024,500));
this.add(panel);
g=this.panel.getGraphics();
Paint(g);
}
public void Paint(Graphics g2)
{
g2=this.panel.getGraphics();
g2.setColor(Color.black);
g2.drawRect(50, 50, 400, 400);
}
}
the eclipse write this messege:
Exception in thread "main" java.lang.NullPointerException
at Paintexample.Paint(Paintexample.java:28)
at Paintexample.init(Paintexample.java:23)
at Main.main(Main.java:9)