Advertisement
advictoriam

Untitled

Mar 4th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.awt.Rectangle;
  2.  
  3. /**
  4.    A tile for tiling the plane.
  5. */
  6. public class Tile extends Rectangle
  7. {
  8.    /**
  9.       Constructs a tile with given dimensions.
  10.       @param x the x-coordinate of the top left corner
  11.       @param y the y-coordinate of the top left corner
  12.       @param width the width of the tile
  13.       @param height the height of the tile
  14.    */
  15.    public Tile(int x, int y, int width, int height)
  16.    {
  17.       super(x, y, width, height);
  18.    }
  19.    
  20.    @Override
  21.    public void translate(int dx, int dy)
  22.    {
  23.       setLocation((int)(getX()+dx*getWidth()), (int)(getY()+dy*getHeight()));
  24.    }
  25.  
  26.  
  27.    // this method is used to check your work
  28.  
  29.    public static String check(int x, int y, int width, int height, int dx, int dy)
  30.    {
  31.       Tile t = new Tile(x, y, width, height);
  32.       t.translate(dx, dy);
  33.       return t.toString();
  34.    }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement