Question: Is a bouncing ball java GUI program. import javax.swing.*; public class BouncingBallDemo extends JFrame{ //DO NOT MODIFY THIS CODE IN THIS CLASS public BouncingBallDemo(){ BouncingBall

Is a bouncing ball java GUI program.

import javax.swing.*;

public class BouncingBallDemo extends JFrame{

//DO NOT MODIFY THIS CODE IN THIS CLASS

public BouncingBallDemo(){

BouncingBall bbdemo = new BouncingBall();

add(bbdemo);

setTitle("Bouncing Ball Demo - LAB 6");

setSize(350,400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}

public static void main(String[] arg){

BouncingBallDemo WINDOW = new BouncingBallDemo();

}

}

--------------------------------------------------------------------------------

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

//DO NOT DELETE ANY LINES FROM THIS CLASS ADD THE LINES NECESSARY TO ANIMATE THE BOUNCING BALL

public class BallContainer extends JPanel{

private Ball ball = new Ball();

private int moveInterval = 35;

private Timer timer;

public BallContainer(){

setPreferredSize(new Dimension(200,120));

setBorder(BorderFactory.createLineBorder(Color.BLACK));

//set up the timer

}

public void setAnimation(boolean isAnimationRunning){

//add if statement start/stop animation

}

public void paintComponent(Graphics canvas){

super.paintComponent(canvas);

//draw the ball

}

class TimerAction implements ActionListener{

public void actionPerformed(ActionEvent e){

//update the ball

}

}

}

---------------------------------------------------------------------------

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class BouncingBall extends JPanel{

BallContainer bcontainer;

public BouncingBall(){

//instantiate components

//create the bcontainter

//create two buttons - start and stop

//add listeners to each button

//create a panel to hold the buttons

setLayout(new BorderLayout());

//add the button panel in the north area

//add the bcontainer to the center;

}

class StartAction implements ActionListener{

public void actionPerformed(ActionEvent e){

bcontainer.setAnimation(true);

}

}

class StopAction implements ActionListener{

public void actionPerformed(ActionEvent e){

bcontainer.setAnimation(false);

}

}

}

---------------------------------------------------------------

import java.awt.*;

//DO NOT DELETE ANY LINES FROM THIS CLASS ADD THE LINES NECESSARY TO ANIMATE THE BOUNCING BALL

public class Ball {

private final static int DIAMETER = 35;

private int xcoord, ycoord;

private int deltaX, deltaY;

private int maxWidth, maxHeight;

public Ball() {

xcoord = 0;

ycoord = 0;

deltaX = deltaY = 2;

}

public void setBounds(int width, int height){

//save the panels width and height -- see line 9

}

/*

* Write the code to move the ball and stay with in the bounds of the container it is in.

*

*/

public void move(){

//update x and y coordinate values

xcoord += deltaX;

ycoord += deltaY;

//change x direction if necessary

if(xcoord <= 0 || xcoord >= maxWidth)

deltaX = deltaX * -1;

//change y direction if necessary

if(ycoord <= 0 || ycoord <= maxHeight)

deltaY = deltaY * -1;

}

/*

* Draws the ball at a new position

*

*/

public void draw(Graphics gObj){

gObj.fillOval(xcoord, ycoord, DIAMETER, DIAMETER);

}

Do the comment lines.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!