Page 1


Week 7 Programming Assignment Documentation 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. 1. All commentary must use standard JavaDoc comments and tags. 2. For every class add a class level comment including the author (Melissa Kapolka) and the purpose of the class. 3. Where one class heavily depends on the use of an object from another class, provide a link to the other class using the @see tag. 4. For every method, add a method level comment which includes information on the purpose of the method, the method parameters, and the result returned by the method. 5. Use the javadoc command to generate HTML files for your project. 6. Use the browser to view your generated documentation to verify that all the required information for all the classes is included. 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, turn in a copy of your JAR file to your instructor. 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’s x-coordinate private int dy = 2; // Increment on ball’s 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(; // Check boundaries if (x < radius) dx = Math.abs(dx); if (x > getWidth() – radius) dx = -Math.abs(dx); if (y < radius) dy = Math.abs(dy); if (y > getHeight() – radius) dy = -Math.abs(dy); // Adjust ball position x += dx;

y += dy; g.fillOval(x – radius, y – radius, radius * 2, radius * 2); } }   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 – paddleWidth, 0, paddleWidth, paddleHeight); display.add(paddle, BorderLayout.SOUTH); } }   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); } }   MAIN CLASS: public class Main { public static void main(String[] args) { new Controller(); } }   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) { } }


Download paddle ball game java  
Read more
Read more
Similar to
Popular now
Just for you