Class Box
- java.lang.Object
-
- Box
-
public class Box extends Object
Complete this class to specify Box objects that are used by the simulation in Program2. - The fields should store the position, the width, the height, and the colour of a box. Each box should have the default start position at (400,300), where 400 is the x location of the center of the box, and 300 is the position of the conveyor belt (i.e. the bottom of the box). - The constructor should create a Box object with the specified height, width, and color. It should call the draw() method to show the box at the default start position. - The moveLeft(double pixels) method should move the box to the left for the specified number of pixels. It should not redraw it. - The getX() method should return the x position of the box. - The getWidth() method should return the width of the box.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
draw()
Draws the box on the screen with the colour, height and width specified by the fields, and centered at the correct position.void
erase()
Erases the box from the UI DO NOT MODIFY THIS METHODdouble
getWidth()
double
getX()
void
moveLeft(double pixels)
Makes the box a given number of pixels to the left.
-
-
-
Constructor Detail
-
Box
public Box(double width, double height, Color color)
Constructor to create a Box.- Parameters:
width
- the width of the boxheight
- the height of the boxcolor
- the color of the box
-
-
Method Detail
-
moveLeft
public void moveLeft(double pixels)
Makes the box a given number of pixels to the left.Movement should only occur on in the y direction.
-
getX
public double getX()
-
getWidth
public double getWidth()
-
draw
public void draw()
Draws the box on the screen with the colour, height and width specified by the fields, and centered at the correct position.
-
erase
public void erase()
Erases the box from the UI DO NOT MODIFY THIS METHOD
-
-