Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application that provides a solution for problem 23.11 by modifying th

ID: 3672159 • Letter: C

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

          }

      

       }

Explanation / Answer

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Ball extends JApplet implements Runnable, MouseListener { private Thread blueBall; private boolean xUp, yUp, bouncing; private int x, y, xDx, yDy; public void init() { xUp = false; yUp = false; xDx = 1; yDy = 1; addMouseListener( this ); bouncing = false; } public void mousePressed( MouseEvent e ) { if ( blueBall == null ) { x = e.getX(); y = e.getY(); blueBall = new Thread( this ); bouncing = true; blueBall.start(); } } public void stop() { if ( blueBall != null ) { blueBall = null; } } public void paint( Graphics g ) { if ( bouncing ) { g.setColor( Color.blue ); g.fillOval( x, y, 10, 10 ); } } public void run() { while ( true ) { try { blueBall.sleep( 100 ); } catch ( Exception e ) { System.err.println( "Exception: " + e.toString() ); } if ( xUp == true ) x += xDx; else x -= xDx; if ( yUp == true ) y += yDy; else y -= yDy; if ( y <= 0 ) { yUp = true; yDy = ( int ) ( Math.random() * 5 + 2 ); } else if ( y >= 190 ) { yDy = ( int ) ( Math.random() * 5 + 2 ); yUp = false; } if ( x <= 0 ) { xUp = true; xDx = ( int ) ( Math.random() * 5 + 2 ); } else if ( x >= 190 ) { xUp = false; xDx = ( int ) ( Math.random() * 5 + 2 ); } repaint(); } } public void mouseExited( MouseEvent e ) {} public void mouseClicked( MouseEvent e ) {} public void mouseReleased( MouseEvent e ) {} public void mouseEntered( MouseEvent e ) {} } - See more at: https://www.gidforums.com/t-12303.html#sthash.BBVl57Af.dpuf

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote