• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement 'UNDO' feature?  RSS feed

 
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need to design 'notepad' application as my assignment.

Requirement: Only text is allowed, all the characters are having same size and font. It should have feature like new, open, save , save as , exit , UNDO , find , replace and font.

For this i use JTextArea and menu bar .

I am able to develop features like new, open, save , save as , exit. Need to implement now UNDO , find , replace and font but struck at 'UNDO'. I do not have any idea how to do it.

UNDO feature should be enable only when user writing in the writing area but not when it opens any file. What i thought is to have a flag on whenever user save whatever he wrote and if he use select UNDO then it check for the flag. If flag is ON then it will not do UNDO and if flag is not set then it cleared everything from the Text Area.

Any one having better idea?
 
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not exactly sure I understand what you suggested, but if it were me, I would want the Undo feature to be independent from the user saving the document. Answer these two questions:

1. What will the Undo command undo?
2. Do you want to allow for multiple consecutive Undo commands?
 
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply put, you would use the undo/redo features which are built into the Java language. Here's the Oracle tutorial: How to Write an Undoable Edit Listener. It's a bit limited in scope but if you do a web search for java undo redo tutorial you'll find more tutorials by other people, which may cover more territory.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will the Undo command undo?


It remove all the unsaved data

Do you want to allow for multiple consecutive Undo commands?


Yes.

Here's the Oracle tutorial: How to Write an Undoable Edit Listener. It's a bit limited in scope but if you do a web search for java undo redo tutorial


Thanks Paul. Let me check this...
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out. Its working fine now. Thanks guy for your advice and i also google it.


 
Paul Clapham
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the undo/redo classes are actually fairly simple to use, aren't they?

Just a comment not related to undo/redo; this code:



can be simplified a lot:


 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the undo/redo classes are actually fairly simple to use, aren't they?


yeah really they are much more simpler then initially i thought about it. Honestly i was scared earlier.

can be simplified a lot:


Thanks for your advice. It indeed reduce typing. I need some more advice from you if it is ok with you? I am writing a notepad application and wrote some functionality. Could you please some of my code to advice how to improve it further?






 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!