Graphic Rendering System 1.0
A Java-based graphic rendering system implementing various design patterns
Loading...
Searching...
No Matches
MoveShapeCommand.java
Go to the documentation of this file.
1package com.example.graphics.command;
2
3import com.example.graphics.model.Shape;
4
9public class MoveShapeCommand implements Command {
10 private final Shape shape;
11 private final int newX;
12 private final int newY;
13 private final int oldX;
14 private final int oldY;
15
22 public MoveShapeCommand(Shape shape, int newX, int newY) {
23 this.shape = shape;
24 this.newX = newX;
25 this.newY = newY;
26 this.oldX = shape.getX();
27 this.oldY = shape.getY();
28 }
29
30 @Override
31 public void execute() {
32 shape.setPosition(newX, newY);
33 }
34
35 @Override
36 public void undo() {
37 shape.setPosition(oldX, oldY);
38 }
39}
MoveShapeCommand(Shape shape, int newX, int newY)