hi there, I need to write these 3 functions, but i got stuck at redo and delete. Redo is showing error when there is nothing to redo and i don't know how to write delete function. Thank you
undo
public class Undo extends AbstractAction {
private MyCanvas myCanvas;
public Undo(MyCanvas myCanvas) {
this.myCanvas = myCanvas;
this.putValue(NAME, "Undo");
this.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl Z"));
this.putValue(SMALL_ICON, new ImageIcon(Main.class.getResource("/icons/Undo24.gif")));
}
public void actionPerformed(ActionEvent e) {
if (!myCanvas.commands.isEmpty()) {
Command cmd = myCanvas.commands.pop();
cmd.undo();
myCanvas.undoneCommands.add(cmd);
myCanvas.repaint();
}
else
System.out.println();
}
}
redo
public class Redo extends AbstractAction {
private MyCanvas myCanvas;
public Redo(MyCanvas myCanvas) {
this.myCanvas = myCanvas;
this.putValue(NAME, "Redo");
this.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl Y"));
this.putValue(SMALL_ICON, new ImageIcon(Main.class.getResource("/icons/Redo16.gif")));
}
public void actionPerformed(ActionEvent e) {
//if (!myCanvas.commands.isEmpty()) {
Command cmd = myCanvas.undoneCommands.pop();
cmd.execute();
myCanvas.commands.add(cmd);
myCanvas.repaint();
//}
// else
System.out.println();
}
}