Question: Create an application that provides a solution for problem 23.11 by modifying the solution implemented from the BouncingBall.doc file (located in the Project 6/Bouncing Ball
Create an application that provides a solution for problem 23.11 by modifying the solution implemented from the BouncingBall.doc file (located in the "Project 6/Bouncing Ball Original Solution").
The modifications are as follows for the new solution.
Remove the "Runnable" interface from "BouncingBallPanel" class. Add the "Runnable" interface to "Ball" class Modify the "mouseClicked" method in the "BouncingBallPanel"class to start the thread after each ball is created. The "Ball" class must receive a reference to the "Bouncing BallPanel" (i.e., to call the "repaint" method) Remove the "run" method from the "BouncingBallpanel" note. The "run" method must be implemented in the "Ball" class. The inner loop of the "run" method must be removed and the single "move" method call should remain. Also modify the method so that the delay for each ball is different (i.e., a way to simulate ball moving at different rates)
PLEASE CAN I GET THE SAMPLE OUT PUT TO THIS QUESTION.THANK YOU
PROBLEM 23.11 PROBLEM 23.11(Java how to Program (Early Objects) 10th Edition)
23.11 (Bouncing Balls) Modify the program in Exercise 23.10 to add a new ball each time the user clicks the mouse. Provide for a minimum of 20 balls. Randomly choose the color for each new ball.
23.10 (Bouncing Ball) Write a program that bounces a blue ball inside a JPanel. The ball should begin moving with a mousePressed event. When the ball hits the edge of the JPanel, it should bounce off the edge and continue in the opposite direction. The ball should be updated using a Runnable.
PLEASE CAN I GET THE SAMPLE PROGRAM TO THIS PROGRAM
Content of BouncingBall.doc
Project 6
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class GUIProgram extends JFrame {
private final int APPLICATION_WIDTH=200;
private final int APPLICATION_HEIGHT=250;
public static void main(String[] args)
{
new GUIProgram();
}
public GUIProgram()
{
JPanel mainpanel=new JPanel();
mainpanel.setLayout(new BorderLayout());
mainpanel.add(createInputPanel(), BorderLayout.NORTH);
mainpanel.add(createButtonPanel(), BorderLayout.CENTER);
add(mainpanel);
setVisible(true);
pack();
setTitle("Calculator");
setSize(APPLICATION_WIDTH, APPLICATION_HEIGHT);;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private JPanel createButtonPanel()
{
JPanel buttonPanel=new JPanel();
buttonPanel.setLayout(new GridLayout(4, 4,5,5));
JButton oneBtn=new JButton("1");
JButton twoBtn=new JButton("2");
JButton threeBtn=new JButton("3");
JButton fourBtn=new JButton("4");
JButton fiveBtn=new JButton("5");
JButton sixBtn=new JButton("6");
JButton sevenBtn=new JButton("7");
JButton eightBtn=new JButton("8");
JButton nineBtn=new JButton("9");
JButton zeroBtn=new JButton("0");
JButton divisionBtn=new JButton("/");
JButton mulBtn=new JButton("*");
JButton subtractBtn=new JButton("-");
JButton addBtn=new JButton("+");
JButton equalBtn=new JButton("=");
JButton dotBtn=new JButton(".");
buttonPanel.add(sevenBtn);
buttonPanel.add(eightBtn);
buttonPanel.add(nineBtn);
buttonPanel.add(divisionBtn);
buttonPanel.add(fourBtn);
buttonPanel.add(fiveBtn);
buttonPanel.add(sixBtn);
buttonPanel.add(mulBtn);
buttonPanel.add(oneBtn);
buttonPanel.add(twoBtn);
buttonPanel.add(threeBtn);
buttonPanel.add(subtractBtn);
buttonPanel.add(zeroBtn);
buttonPanel.add(dotBtn);
buttonPanel.add(equalBtn);
buttonPanel.add(addBtn);
return buttonPanel;
}
private JPanel createInputPanel() {
JPanel inputPanel=new JPanel();
JTextField txtField=new JTextField(20);
inputPanel.add(txtField);
return inputPanel;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
