|
Re: Graphics
|
Posted: Feb 24, 2005 10:38 AM
|
|
1. Wich eror appears if you make paint static?
2. What is the sense of all this? You did not create a frame or anything else to draw something You didn't initialize g (in fact, you can't. You must GET g from somewhere)
Use a class like this:
import javax.*;
import java.awt.*;
import java.awt.geom.*;
public class MyFrame extends JFrame {
public MyFrame () {
this.setSize (640, 480);
}
public void paint(Graphics g){
super.paint (g); // this method overrides the standard paint method of the JFrame, so we better call the standard method first
g.draw(new Line2D.Double (60,50, 300, 500);
}
public static void main (String[] args} {
//do something important
new MyFrame().show();
}
}
This is a very rude example. Normally you would create a class extending JPanel and paint on the panel (of course the panel needs a frame or diaog as parent), but it shows the basics.
|
|