The objective of this part of the lab is to create documentation using Javadoc f
ID: 1812508 • Letter: T
Question
The objective of this part of the lab is to create documentation using Javadoc for the Paddle Ball Game project from Java code below. 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.
When you have successfully executed your JAR file please provide the code.
Explanation / Answer
BALL CLASS:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
* Paddle Ball code using javadoc comments.
* @author Melissa Kapolka
* @verion 1.0
*/
public class Ball extends JPanel {
private int delay = 10;
// Create a timer with delay 1000 ms
private Timer timer = new Timer(delay, new TimerListener());
private int x = 0; private int y = 0; // Current ball position
private int radius = 5; // Ball radius
private int dx = 2; // Increment on ball%u2019s x-coordinate
private int dy = 2; // Increment on ball%u2019s y-coordinate
public Ball() {
timer.start();
}
private class TimerListener implements ActionListener {
/** Handle the action event */
public void actionPerformed(ActionEvent e) {
repaint();
}
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
// Check boundaries
if (x < radius) dx = Math.abs(dx);
if (x > getWidth() %u2013 radius) dx = -Math.abs(dx);
if (y < radius) dy = Math.abs(dy);
if (y > getHeight() %u2013 radius) dy = -Math.abs(dy);
// Adjust ball position
x += dx;
y += dy;
g.fillOval(x %u2013 radius, y %u2013 radius, radius * 2, radius * 2);
}
}
%u2003
CONTROLLER CLASS:
import javax.swing.*;
import java.awt.*;
public class Controller {
private Ball ball = new Ball();
public Controller() {
//The controller has a ball, a paddle, and a display object
Display display = new Display(500,500);
display.setLayout(new BorderLayout());
// Add ball to the display
display.add(ball, BorderLayout.CENTER);
int width = 500;
int paddleWidth = 40;
int paddleHeight = 12;
Paddle paddle = new Paddle(width / 2 %u2013 paddleWidth, 0, paddleWidth, paddleHeight);
display.add(paddle, BorderLayout.SOUTH);
}
}
%u2003
DISPLAY CLASS:
import javax.swing.JFrame;
public class Display extends JFrame{
public Display(int h, int w) {
this.setSize(h,w);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
%u2003
MAIN CLASS:
public class Main {
public static void main(String[] args) {
new Controller();
}
}
%u2003
PADDLE CLASS:
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JPanel;
class Paddle extends JPanel implements MouseMotionListener {
//The Paddle class has a length and a position
private int xpos;
private int ypos;
int widtH;
int heighT;
public Paddle(int xpos, int ypos, int widtH, int heighT) {
this.xpos = xpos;
this.ypos = ypos;
this.widtH = widtH;
this.heighT = heighT;
addMouseMotionListener(this);
}
//The draw method of the Paddle class takes a Graphics object parameter and draws a filled
public void paint(Graphics g) {
super.paintComponent(g);
g.fillRect(xpos, ypos, widtH, heighT);
}
boolean collision(int ballxpos, int ballypos, int ballwidth, int ballheight) {
if ((ballxpos + ballwidth < xpos || ballxpos > xpos + widtH)
|| (ballypos + ballheight < ypos || ballypos > ypos + heighT)) {
return false;
} else {
return true;
}
}
/*
* To support the controller, the Paddle class
must have methods which return the position of the top, bottom, left, and right edges of the this.
*/
void setXpos(int x) {
xpos = x;
}
void setWidth(int widtH) {
this.widtH = widtH;
}
int getXpos() {
return xpos;
}
int getWidtH() {
return widtH;
}
public void mouseDragged(MouseEvent e) {
// Get the new location and repaint the screen
xpos = e.getX();
repaint();
}
public void mouseMoved(MouseEvent e) {
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.