Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final static int ARRAY_MAX = 4;
- public static void swapXY(Movable object) throws NullPointerException
- {
- if (object == null)
- throw new NullPointerException ("Object is not created");
- System.out.println("Coordinates: X = " + object.getX() + ", Y = " + object.getY());
- object.moveTo(object.getY(), object.getX());
- System.out.println("Coordinates was changed: X = " + object.getX() + ", Y = " + object.getY());
- }
- public static void main(String[] args) {
- Point p = new Point(5, 5);
- p.draw(); // 5 5
- p.moveTo(10, 10);
- p.draw(); // 10 10
- p.move(-5, 5);
- p.draw(); // 5 15
- Background b = new Background(10, "mytexture.tt");
- b.draw(); // 10 mytexture.tt
- b.setColor(20);
- b.setTextureName("furt.tt");
- b.draw(); // 20 furt.tt
- Circle c = new Circle(5, 5, 3);
- c.draw(); // 5 5 3
- c.setRadius(10);
- c.moveTo(1, 1);
- c.draw(); // 1 1 10
- Rectangle r = new Rectangle(5, 5, 10, 20);
- r.draw(); // 5 5 10 20
- r.moveTo(1, 1);
- r.setWidth(50);
- r.setHeight(25);
- r.draw(); // 1 1 50 25
- Rectangle e = new Ellipse(2, 2, 10, 15);
- e.draw(); // 2 2 10 15
- e.move(1, 1);
- e.setWidth(40);
- e.setHeight(250);
- e.draw(); // 3 3 40 250
- Point p1 = new Point(15, 16);
- Point p2 = new Point(23, 42);
- //Point p3 = new Point(42, 108);
- Movable movableArray[];
- movableArray = new Movable[ARRAY_MAX];
- movableArray[0] = p;
- movableArray[1] = p1;
- movableArray[2] = p2;
- //movableArray[3] = p3; //
- for (int i = 0; i < ARRAY_MAX; i++) {
- try {
- swapXY(movableArray[i]);
- }
- catch (NullPointerException ex) {
- System.out.println ("Error while swapping coordinates.");
- ex.printStackTrace();
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement