• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applet using push/pop - Beginner Question

 
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic