//COMP 274
//Week 5 Assignment
//Ball File import java.awt.*;
public class Ball
{
//Size of the ball (diameter) int Size; //X, Y position of the ball is the upper left corner of the minimal box containing the ball int X; int Y;
//When the X increment is positive the ball is traveling to the right
//When the X is negative it is traveling to the left int Xincre; //When the Y increment is positive the ball is traveling down
//When the Y is negative it is traveling up int Yincre; public Ball(int diameter, int distance)
{
Size = diameter; Xincre = distance; Yincre = distance;
//Ball starting point(position) X=0; Y=0;
}
public void newPosition(int widthW, int heightH)
{
//Method adds the X increment to the …show more content…
//The getLeft and getRight methods return an X position public void newPosition(int x, int y)
{
XpositionP= x;
}
public int getTop()
{
return YpositionP;
}
public int getBottom()
{
return YpositionP + WidthW;
}
public int getLeft()
{
return XpositionP - lengthL;
}
public int getRight()
{
return XpositionP + lengthL;
}
//Draws the Paddle and sets the color of the Paddle public void drawPaddleP (Graphics …show more content…
//Sets the color of paddle to GREEN graphic.setColor(Color.GREEN);
//Creates the shape of the paddle to be rectangle and how the paddle is positioned graphic.fillRect(XpositionP-lengthL, YpositionP,lengthL, WidthW );
}
}
//Sheree Elder
//COMP 274
//Week 5 Assignment
//Display File
import javax.swing.*; import java.awt.*;
//Class extends the JPanel class public class Display extends JPanel
{
Controller controllerC; JFrame frameF; Display(Controller c) { controllerC = c; //Storing the controller //Creates a frame frameF= new JFrame(); frameF.add(this); frameF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Object will terminate frameF.setSize(600, 600);//Window size to be 600 pixels wide/600 pixels high frameF.setVisible(true);//Window with object becomes visible due to JFrame }
// public void paintComponent(Graphics graphic)
{
graphic.setColor(Color.GRAY);//Sets the background to a color GREY graphic.fillRect(0,0,getWidth(),getHeight()); controllerC.drawgame(graphic);
}
}
//Sheree Elder
//COMP 274
//Week 5 Assignment
//Controller File
import java.awt.*; import java.awt.event.*; import javax.swing.Timer;
//Class must implement the ActionListener interface deal with Timer events which drives the