undo/redo problems

i finally figured out how im going to go about this undo redo function for my paint program however i have come across a problem.

when i press undo, this code is run:

publicvoid undo()

{

Object o = lines.lastElement();

stack.add(o);

int index = lines.lastIndexOf(o);

lines.remove(index);

repaint();

}

"lines" is a vector containing "AngledLines"(my own class which can create lines, squares and circles etc..

the only way i can store the angledline is as an object.

the redo method:

publicvoid redo()

{

Object o = stack.pop();

lines.add(o);

repaint();

}

now this wont compile because i cant add an object to a vector of "angledlines", is there any way to change that object back into an "AngledLine"?

please help, thanks

[1119 byte] By [boblettoj99a] at [2007-11-27 3:16:58]
# 1
Are you using generics?
DrLaszloJamfa at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 2
are generics those things where you have eg vector<AngledLine>because if so..yes
boblettoj99a at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 3
Those are generics. How did you define Stack -- what is its type?
DrLaszloJamfa at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 4
Stack stack = new Stack(); original name huh
boblettoj99a at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 5
Stack is a generic class, too, why not define:Stack < YourClass > stack = new Stack < YourClass > ();
DrLaszloJamfa at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 6

hmm ok its compiling now but its still not doing anything when i press redo..

here is the updates code:

public void undo()

{

AngledLine o = lines.lastElement();

stack.add(o);

int index = lines.lastIndexOf(o);

lines.remove(index);

repaint();

}

public void redo()

{

AngledLine o = stack.pop();

lines.add(o);

repaint();

}

boblettoj99a at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 7
Is it working when you press undo? That seems to be the more basic step --if undoing isn't occurring, I wouldn't hold much hope for redoing...
DrLaszloJamfa at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 8
yup the undo works fine
boblettoj99a at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 9
oh ahaha i got so worked up about getting the code to compile that i actually forgot to assign the method to the buttonall fixed now hehe
boblettoj99a at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...
# 10
Treat yourself to a donut. I am:[url #" style="display: block; background-image: url(' http://www.cultidols.com/images/idols/homer-simpson-50x50.jpg'); width: 50px; height: 50px] [/url]
DrLaszloJamfa at 2007-7-12 8:19:33 > top of Java-index,Java Essentials,New To Java...