You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Point.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package figures;
  13. import java.awt.*;
  14. import java.awt.geom.*;
  15. public class Point extends ShapeFigureElement {
  16. private int _x;
  17. private int _y;
  18. public Point(int x, int y) {
  19. _x = x;
  20. _y = y;
  21. }
  22. public int getX() { return _x; }
  23. public int getY() { return _y; }
  24. public void setX(int x) { _x = x; }
  25. public void setY(int y) { _y = y; }
  26. public void move(int dx, int dy) {
  27. _x += dx;
  28. _y += dy;
  29. }
  30. public String toString() {
  31. return "Point(" + _x + ", " + _y + ")";
  32. }
  33. /** The height of displayed {@link Point}s. */
  34. private final static int HEIGHT = 10;
  35. /** The width of displayed {@link Point}s. -- same as {@link HEIGHT}. */
  36. private final static int WIDTH = Point.HEIGHT;
  37. public Shape getShape() {
  38. return new Ellipse2D.Float((float)getX()-Point.WIDTH/2,
  39. (float)getY()-Point.HEIGHT/2,
  40. (float)Point.HEIGHT,
  41. (float)Point.WIDTH);
  42. }
  43. }