This week's book giveaway is in the Other Open Source APIs forum. We're giving away four copies of Storm Applied and have Sean Allen, Peter Pathirana & Matthew Jankowski on-line! See this thread for details.
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?
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...
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 ]
Joined: Mar 04, 2002
Instead of using a frame from awt I used a swing component and it worked fine. Thanks