whenever Push is used the item that was entered is added to the JtextArea for stack. When the pop button is pushed the item is removed from the stack but it isn't removed from the stack text area. Is there a way to remove the item added last to the stack in the Jtextarea?
Newlines added: text too wide for screen. CR[/edit]
First you get the text from the JTextArea. (You already know how to do that.) Then you remove the last entry you wrote to the so-called "stack" from that text. Finally you write the resulting text, after you did the removal, back to the JTextArea (which you also already know how to do).
I have to say that JTextArea is not really the best choice for a stack, but perhaps this is some kind of assignment and you can't choose something more suitable.
Joined: May 25, 2009
I would like to hear if there is a better way to do this
. . . there are simple ways to catenate Strings (adding them together) but there aren't such easy ways to subtract Strings. Agree about JList; another possibility is to use a StringBuilder to create the text and renew the text every time you pop from your stack.