Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet using push/pop - Beginner Question

 
Betty Christiansen
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have designed an applet to simulate a stack (last-in, first-out) of strings. The applet consists of:

Two JButtons
Two JTextFields
Two JLabels
A TextArea

The user enters text in the first text field then clicks the push button and it goes in the textArea. After entering several strings the user can click the pop button and the top string goes into the second text field. I am a total newbie and am stuck. I can get a string of text to push to the textArea and then pop it out; however I can't stack them LIFO. Most examples I've seen use integers and I'm not sure how to translate the concept to strings. I'm just not sure how the stack concept works even though I read the API webpage. Does anyone have an example that might help me progress.

My code

 
K. Tsang
Bartender
Posts: 3444
13
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are simulating a "stack" why don't you use the Stack class instead of Vector. Better yet, since Stack class is somewhat obsolete in the collections framework, use the Deque class.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Searching for "example java.util.stack" found http://www.easywayserver.com/blog/java-stack-example/, but there are many more results.

I'm not clear why the stack contains JButton objects - shouldn't it contain String objects?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic