Please help me fix the java program below. I keep on getting hello world when I run it AnimatedBall.java import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class AnimatedBall extends JFrame implements ActionListener { private Button btnBounce; // declare a button to play private TextField txtSpeed; // declare a text field to enter private Label lblDelay; private Panel controls; // generic panel for controls private BouncingBall display; // drawing panel for ball Container frame; public AnimatedBall () { // Set up the controls on the applet frame = getContentPane(); btnBounce = new Button ("Bounce Ball"); //create the objects txtSpeed = new TextField("10000", 10); lblDelay = new Label("Enter Delay"); display = new BouncingBall();//create the panel objects controls = new Panel(); setLayout(new BorderLayout()); // set the frame layout controls.add (btnBounce); // add controls to panel controls.add (lblDelay); controls.add (txtSpeed); frame.add(controls, BorderLayout.NORTH); // add panel to top frame.add(display, BorderLayout.CENTER); //add panel to center btnBounce.addActionListener(this); //add action listener setSize(450,500); setVisible(true); } // init method public void paint (Graphics g) { // paint no longer used // we are not painting on the JFrame - remove } // paint method public void actionPerformed (ActionEvent e) { long speed; speed = Long.parseLong(txtSpeed.getText()); //read text field if (e.getSource() == btnBounce) { display.draw(speed); } } // action method } arrow_forward BouncingBall.java import java.awt.*; public class BouncingBall extends Panel { private long delay; // Overridden paint method for painting the BouncingBall panel public void paint( Graphics g ) { super.paint( g ); // calls paint method from Panel. int radius = (getSize().width/10)/2; int Z = getSize().height/2 - radius; int X = (int)(Math.random()*(getSize().width)) + radius; int Y = (int)(Math.random()*(getSize().height)) + radius; int dy = 1; for (int count = 0; count < 1000 ;count++ ) { g.setColor(getBackground()); //get the panel background color to erase g.drawOval(X, Y, 2*radius, 2*radius); if (Y<=0 || Y>=(getSize().height)- 2*radius) { dy = -dy; } Y += dy; g.setColor( Color.BLUE ); g.fillOval(X, Y, 2*radius, 2*radius); try { Thread.sleep(delay); } catch (InterruptedException ex) { } } } // method to set delay value and draw the BouncingBall Panel public void draw(long d) { this.delay = d; repaint(); }
Please help me fix the java program below. I keep on getting hello world when I run it AnimatedBall.java import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class AnimatedBall extends JFrame implements ActionListener { private Button btnBounce; // declare a button to play private TextField txtSpeed; // declare a text field to enter private Label lblDelay; private Panel controls; // generic panel for controls private BouncingBall display; // drawing panel for ball Container frame; public AnimatedBall () { // Set up the controls on the applet frame = getContentPane(); btnBounce = new Button ("Bounce Ball"); //create the objects txtSpeed = new TextField("10000", 10); lblDelay = new Label("Enter Delay"); display = new BouncingBall();//create the panel objects controls = new Panel(); setLayout(new BorderLayout()); // set the frame layout controls.add (btnBounce); // add controls to panel controls.add (lblDelay); controls.add (txtSpeed); frame.add(controls, BorderLayout.NORTH); // add panel to top frame.add(display, BorderLayout.CENTER); //add panel to center btnBounce.addActionListener(this); //add action listener setSize(450,500); setVisible(true); } // init method public void paint (Graphics g) { // paint no longer used // we are not painting on the JFrame - remove } // paint method public void actionPerformed (ActionEvent e) { long speed; speed = Long.parseLong(txtSpeed.getText()); //read text field if (e.getSource() == btnBounce) { display.draw(speed); } } // action method } arrow_forward BouncingBall.java import java.awt.*; public class BouncingBall extends Panel { private long delay; // Overridden paint method for painting the BouncingBall panel public void paint( Graphics g ) { super.paint( g ); // calls paint method from Panel. int radius = (getSize().width/10)/2; int Z = getSize().height/2 - radius; int X = (int)(Math.random()*(getSize().width)) + radius; int Y = (int)(Math.random()*(getSize().height)) + radius; int dy = 1; for (int count = 0; count < 1000 ;count++ ) { g.setColor(getBackground()); //get the panel background color to erase g.drawOval(X, Y, 2*radius, 2*radius); if (Y<=0 || Y>=(getSize().height)- 2*radius) { dy = -dy; } Y += dy; g.setColor( Color.BLUE ); g.fillOval(X, Y, 2*radius, 2*radius); try { Thread.sleep(delay); } catch (InterruptedException ex) { } } } // method to set delay value and draw the BouncingBall Panel public void draw(long d) { this.delay = d; repaint(); }
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Please help me fix the java program below. I keep on getting hello world when I run it
AnimatedBall.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AnimatedBall extends JFrame implements ActionListener
{
private Button btnBounce; // declare a button to play
private TextField txtSpeed; // declare a text field to enter
private Label lblDelay;
private Panel controls; // generic panel for controls
private BouncingBall display; // drawing panel for ball
Container frame;
public AnimatedBall ()
{
// Set up the controls on the applet
frame = getContentPane();
btnBounce = new Button ("Bounce Ball");
//create the objects
txtSpeed = new TextField("10000", 10);
lblDelay = new Label("Enter Delay");
display = new BouncingBall();//create the panel objects
controls = new Panel();
setLayout(new BorderLayout()); // set the frame layout
controls.add (btnBounce); // add controls to panel
controls.add (lblDelay);
controls.add (txtSpeed);
frame.add(controls, BorderLayout.NORTH);
// add panel to top
frame.add(display, BorderLayout.CENTER);
//add panel to center
btnBounce.addActionListener(this);
//add action listener
setSize(450,500);
setVisible(true);
} // init method
public void paint (Graphics g)
{
// paint no longer used
// we are not painting on the JFrame - remove
} // paint method
public void actionPerformed (ActionEvent e)
{
long speed;
speed = Long.parseLong(txtSpeed.getText());
//read text field
if (e.getSource() == btnBounce)
{
display.draw(speed);
}
} // action method
}
arrow_forward
import java.awt.*;
public class BouncingBall extends Panel
{
private long delay;
// Overridden paint method for painting the BouncingBall panel
public void paint( Graphics g )
{
super.paint( g ); // calls paint method from Panel.
int radius = (getSize().width/10)/2;
int Z = getSize().height/2 - radius;
int X = (int)(Math.random()*(getSize().width)) + radius;
int Y = (int)(Math.random()*(getSize().height)) + radius;
int dy = 1;
for (int count = 0; count < 1000 ;count++ )
{
g.setColor(getBackground());
//get the panel background color to erase
g.drawOval(X, Y, 2*radius, 2*radius);
if (Y<=0 || Y>=(getSize().height)- 2*radius)
{
dy = -dy;
}
Y += dy;
g.setColor( Color.BLUE );
g.fillOval(X, Y, 2*radius, 2*radius);
try
{
Thread.sleep(delay);
}
catch (InterruptedException ex)
{
}
}
}
// method to set delay value and draw the BouncingBall Panel
public void draw(long d)
{
this.delay = d;
repaint();
}
} // end class BouncingBall
BouncingBall.java
import java.awt.*;
public class BouncingBall extends Panel
{
private long delay;
// Overridden paint method for painting the BouncingBall panel
public void paint( Graphics g )
{
super.paint( g ); // calls paint method from Panel.
int radius = (getSize().width/10)/2;
int Z = getSize().height/2 - radius;
int X = (int)(Math.random()*(getSize().width)) + radius;
int Y = (int)(Math.random()*(getSize().height)) + radius;
int dy = 1;
for (int count = 0; count < 1000 ;count++ )
{
g.setColor(getBackground());
//get the panel background color to erase
g.drawOval(X, Y, 2*radius, 2*radius);
if (Y<=0 || Y>=(getSize().height)- 2*radius)
{
dy = -dy;
}
Y += dy;
g.setColor( Color.BLUE );
g.fillOval(X, Y, 2*radius, 2*radius);
try
{
Thread.sleep(delay);
}
catch (InterruptedException ex)
{
}
}
}
// method to set delay value and draw the BouncingBall Panel
public void draw(long d)
{
this.delay = d;
repaint();
}
} // end class BouncingBall
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY