The Task (Task should be in Java format) You are going to write code of a graphics application. The application displays a red 2D ball on the frame. When user holds and releases the ball to a certain...

1 answer below »


The Task (Task should be in Java format)


You are going to write code of a graphics application. The application displays a red 2D ball on the frame. When user holds and releases the ball to a certain direction the ball begins to bounce.



Deliverables


Source code in Eclipse project format



How to Submit


Add your files to a folder named as your lastname_surname, zip it and upload to the related Sucourse assignment.



Business Rules:



  • When the application starts the ball will be displayed as still.

  • User will hold the ball with the pointer and release it to a certain direction, then the ball will begin moving.

  • When the ball hits a border of JFrame, it will make a 45 degrees bounce on the border according to the direction it is moving.

  • When the frame is resized, ball must move accordingly. It shouldn’t go out of the borders of the frame.

  • When the user clicks and holds the mouse, the ball will stop bouncing and move to the pressed coordinates. The user might throw the ball to a different direction then. If the user doesn’t throw and just release the mouse, the ball will continue with its previous bouncing pattern.



Hints



  • Always increase / decrease the X and Y position of the ball by 1 pixel, so it will make a 45 degrees angle when bouncing.

  • For dragging the ball implement MouseInputAdapter overriding mouseDragged() method on the container.

  • Use a thread to bounce the ball updating paint() method of the container on every run.

Answered 1 days AfterMar 14, 2021

Answer To: The Task (Task should be in Java format) You are going to write code of a graphics application. The...

Shweta answered on Mar 16 2021
132 Votes
77697/turi_kaya.zip
turi_kaya/.classpath

    
        
            
        
    
    
    
turi_kaya/.project

     turi_kaya
    
    
    
    
        
             org.eclipse.jdt.core.javabuil
der
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
turi_kaya/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
turi_kaya/bin/turi_kaya/BouncingBall$1.class
package turi_kaya;
synchronized class BouncingBall$1 extends Thread {
void BouncingBall$1(BouncingBall);
public void run();
}
turi_kaya/bin/turi_kaya/BouncingBall.class
package turi_kaya;
public synchronized class BouncingBall extends javax.swing.JPanel implements java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener {
int width;
int height;
Thread thread;
float radius;
float diameter;
float X;
float Y;
float dx;
float dy;
public void BouncingBall();
public void paintComponent(java.awt.Graphics);
public void actionPerformed(java.awt.event.ActionEvent);
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here