File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Applet using push/pop - Beginner Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Meteor in Action this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet using push/pop - Beginner Question" Watch "Applet using push/pop - Beginner Question" New topic

Applet using push/pop - Beginner Question

Betty Christiansen

Joined: Apr 12, 2014
Posts: 28
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

Joined: Sep 13, 2007
Posts: 2812

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

Joined: Mar 22, 2005
Posts: 42955
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?
subject: Applet using push/pop - Beginner Question