How do you pause a program until a button is pressed in JAVA?

Java Programming - jLabel Question?

  • Hey guys- So in my program, I have a button that generates random numbers. When the generate button is pressed (by the user), I want one of the labels to update with the random number it generated. I am using a NetBeans Desktop Application. I know that jLabels have a .SetText property, but I can't even find the variable name that I named the label, in my class for the random numbers. How would I change the text after the user clicks the button? It looks like the labels were created in a class called GameView, and I am trying to reference them in another class called RNG. They were declared Private (automagically), and you cannot change this code. Help!

  • Answer:

    You need to use an action listener with the button and add the code for changing the text in the label there. Since you posted no code and I don't know what your GameView class contains, that is the best advice I can give. http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html

Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

You need to use an action listener with the button and add the code for changing the text in the label there. Since you posted no code and I don't know what your GameView class contains, that is the best advice I can give. http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.