|
-
January 12th, 2010, 01:12 PM
#1
undo, redo and delete function
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
Code:
package zadani21.commands;
import zadanie21.Command;
import zadanie21.Main;
import zadanie21.MyCanvas;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
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
Code:
package zadani21.commands;
import zadanie21.Command;
import zadanie21.Main;
import zadanie21.MyCanvas;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
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();
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|