i'm trying to draw a little drawing using some values from other class (a physics problem). What I want is translate the results of that problem to the drawing. For example, x and y for an arc symbolizing a parabolic shot.
My problem is that I don`t know how to call the paint() method to write everything translating these values. The execution shows JavaNullPointerException. This is my code:
public class Draw extends JFrame {
private Calculate c;
public Draw() {
super("Title");
setSize(1000, 500);
setVisible(true);
}
public void paint(Graphics g, int x, int y, int alpha) {
super.paint(g);
g.setColor(Color.RED);
g.drawLine(0, 30, 350, 30);
g.setColor(Color.BLUE);
g.drawRect(200, 100, 450, 250);
g.drawString("x = 10 cm", 400, 90);
g.drawString("y = 2 cm", 670, 200);
//g.drawLine(200, 350, 450, 250);
g.drawArc(200, 350, x, y, alpha, 70);
}
public static void main(String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
Draw aplication = new Draw();
aplicacion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
And main class:
public class Main{
public static void main(String[] args) {
//45 means alpha
Calculate c = new Calculate(45, (int) (5.0*(Math.pow(10, 6))));
Graphics g = new Graphics() {..};
Draw d = new Draw();
//After everything is calculated
d.paint(g, c.getX(), c.getY(), c.getAlfa());
}
}