aspose file tools*
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
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet using push/pop - Beginner Question" Watch "Applet using push/pop - Beginner Question" New topic
Author

Applet using push/pop - Beginner Question

Betty Christiansen
Greenhorn

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

Joined: Sep 13, 2007
Posts: 2596
    
    9

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42611
    
  65
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?


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet using push/pop - Beginner Question