This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.