How to use threads for this scenario???????

S

steve smith

Hi here is the problem I have I have a panel consisting of radio
buttons, the buttons are disabled. Each button is associated with a
value, and when the counter hits that value the button should be
enabled. The counter is incremented by the user by means of a jButton.
I tried implementing this by having a while loop which continously
checked for the counter reaching any of the values of the radio
buttons so that they could become enabled, only when i ran the program
it would completely crash. I think the best option would be to use
threads to do this but I have never used threads before and so would
like some help on how I should go about this problem? Thanks.
 
M

Marc Rochkind

Hi here is the problem I have I have a panel consisting of radio
buttons, the buttons are disabled. Each button is associated with a
value, and when the counter hits that value the button should be
enabled. The counter is incremented by the user by means of a jButton.
I tried implementing this by having a while loop which continously
checked for the counter reaching any of the values of the radio
buttons so that they could become enabled, only when i ran the program
it would completely crash. I think the best option would be to use
threads to do this but I have never used threads before and so would
like some help on how I should go about this problem? Thanks.

Threads sounds like overkill for this case. It seems more straightforward
to me to just program it to enable the button when the appropriate value is
reached.

--Marc
 
T

Thomas G. Marshall

On [GMT+1=CET],
Thomas G. Marshall <[email protected]>
horrified us with:

....[self snipping]...
General Warning: Be very careful of when you call /any/ swing mutator
method, since swing is /not/ thread safe in general with very few
exceptions. Outside of event handler threads you usually must modify
JComponents by setting the modification for later execustion in the
event handler thread by calling

SwingUtilities.invokeLater();


Note that this was just a general warning.

I should have been exceeding precise here: The JButton listener that I was
talking about /will/ run in the event thread. Within that thread you can
access all swing mutators safely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top