Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Applet using push/pop - Beginner Question

Posts: 28
  • 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

Posts: 3648
Mac OS X Firefox Browser 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.
Posts: 43016
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Searching for "example java.util.stack" found, but there are many more results.

I'm not clear why the stack contains JButton objects - shouldn't it contain String objects?
Crusading Chameleon likes the size of this ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic