import java.awt.*; /** * Write a description of class Box here. * * @author (your name) * @version (a version number or a date) */ public class Box { // instance variables - replace the example below with your own private int x,y,width, direction, leftLimit, rightLimit ; private boolean falling; /** * Constructor for objects of class Box */ public Box(int x, int y, int width) { // initialise instance variables this.x =x; this.y =y; direction = 1; this.width = width; leftLimit = x; rightLimit = x+6*width; falling=false; } public void draw(Graphics g) { // put your code here g.setColor(Color.BLUE.darker()); g.fillRect(x,y, width,width); } public void move() { if(direction ==0) return; int next = 20*direction; if ( x+next > rightLimit ) { direction = -1; } if ( x+next < leftLimit ) { direction = 1; } if (falling){ y += next; }else{ x += next; } } public void stop(){ direction =0; falling=true; } }