File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Set up a loop for a frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Set up a loop for a frame" Watch "Set up a loop for a frame" New topic

Set up a loop for a frame

Chad Moore

Joined: Mar 04, 2002
Posts: 7
I have this situation: I made a frame that asks the user to enter a string and then click a button when finished. Then, I get the string, do some operations on it, and then display an output to the DOS console. I have that part completed. My objective now is set a loop that can count the number of clicks the user presses. I want the user to enter 5 strings. Once the 5th string is entered I do not want it to accept anymore. The frame may or may not stay open, that does not matter. I just do not want it to accept anymore input. Using just java.awt.* for displaying the frame ,is it possible to do this? The trouble I am running in to is that the every time the user enters a string the counter will increment but then reset to zero. That was using a local variable. Then, I declared a static variable counter and tried the same thing. This time it would display the message and increment the counter to 5 and then stop. It would do this on every input. I am setting the loop up in the button event handler. If I try to set up the loop in main, it displays five separate frames. Can anyone guide me to some help about this?
Matthew Margolis
Ranch Hand

Joined: Sep 29, 2001
Posts: 32
if you post your code I am sure we could help you better. As for counting 5 inputs thats relatively easy you probably just have a little error hidden in your code that is making that a challange.
I really wouldn't use mouse clicks to count input but if you really want to check out
mouse click tutorial
You will still have to use a counter variable though...
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
You don't need a loop. In your actionPerformed for the button, increment your counter and do your processing. It will only get executed when the button is pushed. If this is what you are currently doing, post your code. As Matthew said it is probably something easy.
[ April 30, 2002: Message edited by: Paul Stevens ]
Chad Moore

Joined: Mar 04, 2002
Posts: 7
Instead of using a frame from awt I used a swing component and it worked fine.
I agree. Here's the link:
subject: Set up a loop for a frame
It's not a secret anymore!