undo, redo and delete function
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: undo, redo and delete function

  1. #1
    Join Date
    Jan 2010
    Posts
    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();
    	}
    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: undo, redo and delete function

    Quote Originally Posted by ivan12yu2000 View Post
    Redo is showing error when there is nothing to redo
    That's probably because the check to see if the command stack is empty has been commented out. Are you sure this is your code?

    i don't know how to write delete function.
    Perhaps if you explained what this program was supposed to do, and what the delete method was supposed to do, we might be able to suggest something.

    Why do we never have time to do it right, but always have time to do it over?
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center