Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-19-2007, 06:00 PM
Member
 
Join Date: Nov 2007
Posts: 1
new214 is on a distinguished road
undo java
Heya al Ive got a JAVA chess program that works in the console area just wanted to know how would I be able to add a undo function that allows the person playing to undo their moves???
Where would I start - ive come across java.swing.undo but not sure????
I cant post any code yet but just want to know am I going along the right lines with using java.swing.undo- bearing in mind this is a console application???
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-20-2007, 11:16 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
You could make up a class called Move which stores the information for each move such as:
token: knight, pawn, etc.
row and column moved from
row and column moved to.
And make up a class that keeps/manages these Moves for a player. You could keep them (the Moves) in an ArrayList or a similar array–type structure. Each player would have an instance of this class which tracked their moves. To undo a move would be as simple as removing the last Move from the list, reversing the player's last move using the data in the removed Move instance, and then discarding this Move instance.
It might be enough to keep (only) an ArrayList of Moves for each player or you may want to make up a separate class (as mentioned above), using an instance of it for each player, that keeps the ArrayList and could provide methods for updating the game with the undo activity.
If you did make this second class, say UndoManager, it could be updated from the Game class and could, as part of its undo support, make updates in/to the game class to reflect each undo operation. So a call to your undoManager.remove() would automatically update the game model and its view in the console.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
add an undo listener to a Jtable christina Advanced Java 4 12-02-2008 11:01 PM
Undo Folder Drag and Drop natel Eclipse 0 04-09-2008 01:01 AM
Undo shortcut malfunctioning. Eranga NetBeans 0 03-31-2008 07:12 AM
java copy paste cut and undo functions Mr tuition AWT / Swing 1 12-09-2007 02:02 AM


All times are GMT +3. The time now is 04:42 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org