Results 1 to 3 of 3
Thread: Help with DrawingPanel
- 01-20-2012, 02:52 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 6
- Rep Power
- 0
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:
Java 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; } }
-
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, 03:28 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 6
- Rep Power
- 0
Re: Help with DrawingPanel
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/
Link to code is: www.buildingjavaprograms.com/DrawingPanel.javaLast edited by Shea6892; 01-20-2012 at 03:33 AM.
Similar Threads
-
problem in DrawingPanel
By Nes_java in forum AWT / SwingReplies: 2Last Post: 04-04-2011, 04:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks