Results 1 to 3 of 3
- 11-08-2011, 04:58 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
My ellipses on my JFrame disappear every time i try to maximize the window!!!!!!!!
Hi I'm doing a project for school and my homework program is due tomorrow here's my code:
Java Code:/** This class simulates a cannonball fired at an angle. */ public class Cannonball { /** Constructs a Cannonball @param ivel the initial velocity of the ball @param angle the angle at which the cannonball was launched (in degrees) */ public Cannonball(double ivel, double angle) { velocity = ivel; angleDegrees = angle; posX = 0; posY = 0; velocityX = velocity * Math.cos(Math.toRadians(angleDegrees)); velocityY = velocity * Math.sin(Math.toRadians(angleDegrees)); } /** Updates the position and velocity of this cannon ball after a given time interval. @param deltaT the time interval */ public void move(double deltaT) { posX += velocityX * deltaT; posY += velocityY * deltaT; velocityY -= G* deltaT; } /** Gets the x position of this cannon ball. @return the horizontal position */ public double getX() { return posX; } /** Gets the y position of this cannon ball. @return the vertical position */ public double getY() { return posY; } private double angleDegrees; private double posY; private double posX; private double velocity; private double velocityX; private double velocityY; public static final double G = 9.81; }Java Code:import javax.swing.JComponent; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import javax.swing.JPanel; /** Draws the trajectory of a cannonball. */ public class CannonballComponent extends JComponent { /** Constructs a component that paints the flight of a cannonball @param ivel the initial velocity of the ball @param ang the angle at which the cannonball was launched */ public CannonballComponent(double ivel, double ang) { ball = new Cannonball(ivel, ang); } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; while(ball.getY() >= 0) { for (int i = 1; i < 10; i++) { ball.move(DELTA_T); } Ellipse2D.Double circle = new Ellipse2D.Double(300 - ball.getX(), 200 - ball.getY(), 5, 5); g2.draw(circle); } } private Cannonball ball; public static final double DELTA_T = 0.01; }Please tell me what is wrong with my code and how to fix it. Thanks in advance! Much appreciated!!!Java Code:import javax.swing.JFrame; import javax.swing.JOptionPane; /** This is a driver for taking a screen snapshot of the CannonballComponent class. */ public class CannonballSnap { public static void main(String[] args) { JFrame frame = new JFrame(); final int FRAME_WIDTH = 300; final int FRAME_HEIGHT = 300; frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); frame.setTitle("CannonballViewer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); double ivel = 50; double ang = 45; CannonballComponent component = new CannonballComponent(ivel, ang); frame.add(component); frame.setVisible(true); } }
-
Re: My ellipses on my JFrame disappear every time i try to maximize the window!!!!!!!
looks like a duplicate post. Locking.
- 11-08-2011, 05:12 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: My ellipses on my JFrame disappear every time i try to maximize the window!!!!!!!
I'm not trying to be a smart@ss, but it really is up to you to tell us what is wrong with the code.Please tell me what is wrong with my code and how to fix it.
Don't be panicked by the approaching deadline. Take your time and say whether the code compiles. If it does not and you can't understand the compiler's messages, copy and post those messages.
If it does compile but at runtime does not do what you expect/intend/desire, then describe what it does do (including the full stack trace of any runtime exception if you get one) and describe what you expected/intended/desired.
Similar Threads
-
How to Maximize the JFrame ?
By MarMer in forum AWT / SwingReplies: 5Last Post: 06-07-2011, 05:19 AM -
Only one Jframe window will be opened at time
By Zamioculcas in forum New To JavaReplies: 4Last Post: 05-29-2011, 01:08 PM -
Disable Maximize button in JFrame?
By Manish87 in forum AWT / SwingReplies: 0Last Post: 02-01-2011, 03:39 PM -
how to disable minimize and maximize button in jframe window
By santhosh_el in forum AWT / SwingReplies: 6Last Post: 11-22-2010, 11:55 AM -
results to code disappear too fast for DOS window
By dubdubdub in forum New To JavaReplies: 3Last Post: 12-29-2007, 05:07 PM


LinkBack URL
About LinkBacks

Bookmarks