Undo Function in Java

J

JavaNewBie

Dear Friends,

We are developing the software in java and my developers are giving me
excuse that the JAVA is not compatible for the following but as i have
read a lot good things about java i want to have a second opinion from
you guys.

In the application we have UNDO functionality which is derived from the
SWING now what i asked to my developer that on click of a button all
the exisiting events for UNDO should be clear.

Example:

In the program we have button CLEAR EVENTS

Now the event start.

1. EVENT 1
2. Press of enter
3. Copy Text
4. Paste Text
5. CLICK BUTTON CLEAR EVENT
6. Enter Line " THIS IS TEST"

Now the result i expect is before the CLEAR EVENT BUTTON IS clicked the
4 events of

1. EVENT 1
2. Press of enter
3. Copy Text
4. Paste Text

Should be possible to UNDO

but when click the CLEAR EVENT on the events after should be able to
UNDO and not the events before the button is clicked.

Here i mean the UNDO should not be possible after CLEAR EVENT BUTTON Is
clicked.

Is it possbilbe.

Please suggest.

Your earlier reply would be a great help to me.

Best regards
Shal
 
O

Oliver Wong

JavaNewBie said:
Dear Friends,

We are developing the software in java and my developers are giving me
excuse that the JAVA is not compatible for the following but as i have
read a lot good things about java i want to have a second opinion from
you guys.

In the application we have UNDO functionality which is derived from the
SWING now what i asked to my developer that on click of a button all
the exisiting events for UNDO should be clear.

Example:

In the program we have button CLEAR EVENTS

Now the event start.

1. EVENT 1
2. Press of enter
3. Copy Text
4. Paste Text
5. CLICK BUTTON CLEAR EVENT
6. Enter Line " THIS IS TEST"

Now the result i expect is before the CLEAR EVENT BUTTON IS clicked the
4 events of

1. EVENT 1
2. Press of enter
3. Copy Text
4. Paste Text

Should be possible to UNDO

but when click the CLEAR EVENT on the events after should be able to
UNDO and not the events before the button is clicked.

Here i mean the UNDO should not be possible after CLEAR EVENT BUTTON Is
clicked.

Is it possbilbe.

Please suggest.

Your earlier reply would be a great help to me.

Yes, it's possible, and very easy, assuming you have a reasonable design
for your undo system. In a typical design, for every undo-able action (or
what you call an "event"), you would create an object representing the
action that was performed, and store it in a linked list.

To undo an action, you would simply look at the tail of the list to see
what the last action was, and then do its inverse (e.g. if it was the
pasting of a certain text, you would "unpaste", or delete the text).

The implementation for your "Clear event" button would simply be to
clear the linked list.

- Oliver
 
T

Tor Iver Wilhelmsen

You need an undoable action. In particular you could look into the
UndoableEdit interface in javax.swing.undo and that package in
particular.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top