The objective of this part of the lab is to create documentation using Javadoc f
ID: 3528328 • Letter: T
Question
The objective of this part of the lab is to create documentation using Javadoc for the Paddle Ball Game project from week 5. The following documentation requirements must be met.
Consult the document provided describing how to export JavaDoc comments from Eclipse.
When your documentation is complete, turn in one of the following depending on what your instructor requires:
1. Print outs of all the documentation pages from the browser.
2. A Zip file containing all the documentation pages.
Deployment
Create a JAR file for the Paddle Ball Game project from week 5. The JAR file must contain all the class files needed to make the Paddle Ball Game work. Consult the document provided describing how to export a JAR file from Eclipse. To test if you have made your JAR file correctly, double click on your JAR file using Windows Explorer. The Paddle Ball Game should start running. If you are on Citrix, you will need to copy your game to a local computer before you can successfully execute it.
Here is the week 5 requirments that will dictate the JAR file.
public class BallGameTest
{
public static void main (String [] args)
{
BallGame world = new BallGame("Ball game");
world.setVisible(true);
world.move( );
}
}
import java.awt.Graphics;
import java.awt.event. *;
public class BallGame extends MovingBall
{
private Paddle myPaddle = new Paddle(FRAME_WIDTH, FRAME_HEIGHT);
public BallGame (String title)
{
super(title);
addKeyListener(new KeyList( ));
}
public void paint (Graphics g)
{
super.paint(g);
if (isContact( ))
{
myBall.bounce( );
}
else
{
myPaddle.paint(g);
}
}
public boolean isContact( )
{
if (myPaddle.area( ).contains(myBall.getPosition( )))
{
return true;
}
else
{
return false;
}
}
// inner class for the listener
private class KeyList extends KeyAdapter
{
public void keyPressed (KeyEvent k)
{
if (k.getKeyCode( ) == KeyEvent.VK_LEFT)
{
myPaddle.moveLeft( );
}
if (k.getKeyCode( ) == KeyEvent.VK_RIGHT)
{
myPaddle.moveRight( );
}
} // ends method keyPressed
} // ends private class KeyList
} // ends class BallGame
import java.awt. *; import javax.swing. *; import java.awt.event. *;
public class MovingBall extends JFrame
{
protected final int FRAME_WIDTH = 240;
protected final int FRAME_HEIGHT = 320;
protected Ball myBall = new Ball(FRAME_WIDTH, FRAME_HEIGHT);
public MovingBall (String title)
{
super(title);
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint (Graphics g)
{
super.paint(g);
myBall.paint(g);
}
public void move ( )
{
while (true)
{
myBall.move( );
repaint( );
try
{
Thread.sleep(50);
}
catch (InterruptedException e)
{
System.exit(0);
}
} // ends while
} // ends move
} // ends MovingBall
import java.awt. *;
public class Ball
{
private final int RADIUS = 10;
private Point pos;
private Color ballColour = Color.red;
private int yChange = 2;
private int xChange = 1;
private int height, width;
public Ball (int frameWidth, int frameHeight)
{
width = frameWidth; height = frameHeight; pos = new Point ( );
pos.x = (int)(Math.random( ) * (width - RADIUS)) + RADIUS;
pos.y = (int)(Math.random( ) * (height/2 - RADIUS)) + RADIUS;
}
public void paint (Graphics g)
{
g.setColor(ballColour);
g.fillOval(pos.x - RADIUS,
pos.y - RADIUS, 2 * RADIUS, 2 * RADIUS);
}
public void move ( )
{
if (pos.y < RADIUS)
{
yChange = -yChange;
}
if (pos.x < RADIUS)
{
xChange = -xChange;
}
if (pos.x > width - RADIUS)
{
xChange = -xChange;
}
if (pos.y < height - RADIUS)
{
pos.translate(xChange, yChange);
}
if (pos.x < width - RADIUS)
{
pos.translate(xChange, yChange);
}
}
public void bounce ( )
{
yChange = -yChange;
pos.translate(xChange, yChange);
}
public Point getPosition ( )
{
return pos;
}
}
import java.awt. *;
import java.awt.event. *;
import javax.swing. *;
public class Paddle
{
private Color paddleColour = Color.blue;
private int x, y;
private int paddleWidth = 20;
private int paddleHeight = 10;
private int move = 5;
public Paddle (int frameWidth,int frameHeight)
{
x = (int)(Math.random( ) * (frameWidth - paddleWidth));
y = frameHeight - paddleHeight;
}
public void moveRight ( )
{
x = x + move;
}
public void moveLeft ( )
{
x = x - move;
}
public Rectangle area ( )
{
return new Rectangle(x, y, paddleWidth, paddleHeight);
}
public void paint (Graphics g)
{
g.setColor(paddleColour);
g.fillRect(x, y, paddleWidth, paddleHeight);
}
Explanation / Answer
public class BallGameTest { public static void main (String [] args) { BallGame world = new BallGame("Ball game"); world.setVisible(true); world.move( ); } } import java.awt.Graphics; import java.awt.event. *; public class BallGame extends MovingBall { private Paddle myPaddle = new Paddle(FRAME_WIDTH, FRAME_HEIGHT); public BallGame (String title) { super(title); addKeyListener(new KeyList( )); } public void paint (Graphics g) { super.paint(g); if (isContact( )) { myBall.bounce( ); } else { myPaddle.paint(g); } } public boolean isContact( ) { if (myPaddle.area( ).contains(myBall.getPosition( ))) { return true; } else { return false; } } // inner class for the listener private class KeyList extends KeyAdapter { public void keyPressed (KeyEvent k) { if (k.getKeyCode( ) == KeyEvent.VK_LEFT) { myPaddle.moveLeft( ); } if (k.getKeyCode( ) == KeyEvent.VK_RIGHT) { myPaddle.moveRight( ); } } // ends method keyPressed } // ends private class KeyList } // ends class BallGame import java.awt. *; import javax.swing. *; import java.awt.event. *; public class MovingBall extends JFrame { protected final int FRAME_WIDTH = 240; protected final int FRAME_HEIGHT = 320; protected Ball myBall = new Ball(FRAME_WIDTH, FRAME_HEIGHT); public MovingBall (String title) { super(title); setSize(FRAME_WIDTH, FRAME_HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paint (Graphics g) { super.paint(g); myBall.paint(g); } public void move ( ) { while (true) { myBall.move( ); repaint( ); try { Thread.sleep(50); } catch (InterruptedException e) { System.exit(0); } } // ends while } // ends move } // ends MovingBall import java.awt. *; public class Ball { private final int RADIUS = 10; private Point pos; private Color ballColour = Color.red; private int yChange = 2; private int xChange = 1; private int height, width; public Ball (int frameWidth, int frameHeight) { width = frameWidth; height = frameHeight; pos = new Point ( ); pos.x = (int)(Math.random( ) * (width - RADIUS)) + RADIUS; pos.y = (int)(Math.random( ) * (height/2 - RADIUS)) + RADIUS; } public void paint (Graphics g) { g.setColor(ballColour); g.fillOval(pos.x - RADIUS, pos.y - RADIUS, 2 * RADIUS, 2 * RADIUS); } public void move ( ) { if (pos.yRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.