# Thread: My ellipses on my JFrame disappear every time i try to maximize the window!!!!!!!!

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;

}

/**
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;

}```
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.setVisible(true);
}
}```
Please tell me what is wrong with my code and how to fix it. Thanks in advance! Much appreciated!!!

2. ## Re: My ellipses on my JFrame disappear every time i try to maximize the window!!!!!!!

looks like a duplicate post. Locking.

3. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,717
Rep Power
16

## Re: My ellipses on my JFrame disappear every time i try to maximize the window!!!!!!!

Please tell me what is wrong with my code and how to fix it.
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.

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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•