# Help with DrawingPanel

• 01-20-2012, 03:52 AM
Shea6892
Help with DrawingPanel
For a homework assignment I have to alter some code to plot points of the calculations of a projectile's trajectory in the Drawing Panel but I can't seem to get any ideas on how to do this as I am reading around and in my book. I would appreciate anybody who can help thanks. Here is the code at the moment:

Code:

```import java.awt.*; import java.util.*; public class ProjectileGraph {         public static final double ACCELERATION = -9.81;         public static void main(String[] args){                 DrawingPanel panel = new DrawingPanel(420, 220);                 Graphics g = panel.getGraphics();                 Scanner console = new Scanner(System.in);                         System.out.println("Velocity (meters/second)? ");                 double velocity = console.nextDouble();         System.out.println("Angle (degrees)? ");                 double angle = Math.toRadians(console.nextDouble());         System.out.println("Number of steps to display? ");                 int steps = console.nextInt();         System.out.println();                 double xVelocity = velocity * Math.cos(angle);         double yVelocity = velocity * Math.sin(angle);         double totalTime = -2.0 * yVelocity / ACCELERATION;         double timeIncrement = totalTime / steps;         double xIncrement = xVelocity * timeIncrement;                 double x = 0.0;         double y = 0.0;         double t = 0.0;                 for(int i = 1; i <= steps; i++){                 t += timeIncrement;                 x += xIncrement;                 y = yVelocity * t + 0.5 * ACCELERATION * t * t;                 System.out.println(i + "\t" + round2(x) + "\t" + round2(y) + "\t" + round2(t));                 }         }         public static double round2(double n) {                 return Math.round(n * 100.0) / 100.0;         } }```
• 01-20-2012, 04:14 AM
Fubarable
Re: Help with DrawingPanel
We have no idea what your DrawingPanel class is like, so I'm not sure how we can be able to help you. Also, if this is Swing or AWT, have you been told specifically by your instructor to call the getGraphics() method?
• 01-20-2012, 04:28 AM
Shea6892
Re: Help with DrawingPanel
Quote:

Originally Posted by Fubarable
We have no idea what your DrawingPanel class is like, so I'm not sure how we can be able to help you. Also, if this is Swing or AWT, have you been told specifically by your instructor to call the getGraphics() method?

Ahhh sorry still very new to java and adding source files and what not. It is AWT and the reference book which the code is out of calls for the getGraphics() method in all the similar example programs but none of them are quite like this where it has to input the calculations as the plotted points, and am not sure what to use(as far as the drawLine,drawRect, etc. methods) because I didn't see a plot point method. But this is the DrawingPanel class I have been told to use and if you can help thanks a ton but if not thanks for the reply.

Edit: mistake in code. I guess the java class is too many characters to post even in code tags. It is from http://www.buildingjavaprograms.com/