473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to wait for a button click?

1
I have this code where I want to get user input in the middle of a loop. So it will look something like this:

do{
//wait for user input
//code to be executed based on user input
}while(true)

If I were to use a Scanner, the program will wait for the user to enter the information, and then it will proceed with the code.
However, I would like to use a JButton instead, so user input is interpreted based on the button clicked.
How would I force the program to wait until the user has clicked a button?
May 4 '12 #1
1 12561
A loop would not be the best solution in this situation. There are things in Java called event handlers. The event handler is like a "listener" (in your case the telling the program to wait part). The listener will wait for the user to press the button. The listener will act appropriately to what you want the button to do.

Here is a link you might want to check out.

http://docs.oracle.com/javase/tutori...nts/intro.html
May 14 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
4
by: Mark Lingen | last post by:
I've found a problem with postback event handling and webcontrol buttons. Try out the following code in an ASP.Net project and you will see. Create a web project in VB.Net and drop this code...
11
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
7
by: code100579 | last post by:
Hi there, sorry if this is a really simple question. I need to write code for: If a button is pushed and then one variety of other buttons is pushed then certain options on the program will...
7
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, I create button in the code ( Dim Button as new Button), not using button web component (means not drap button and drop it ont he webform), after that I try to use button_click event,...
3
by: GauravGupta | last post by:
i want to know that is it posible to call button click event before page load event on post back.... please help me....
10
by: Sebouh | last post by:
Hi guys. I don't know how to implement this so i was hoping if any of you can help me. I have a code like this one: public static void main (String args) { //create frame and button ...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
2
by: tshad | last post by:
Is there an easy way to wait on a button click? I want to be able to show a div and then when the user presses the mouse button, to then hide the div. I can make it happen with a setTimeout to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.