| Author |
Problem whit ActionListener and static variable
|
DanielCosta Sobrinho
Greenhorn
Joined: Jun 06, 2003
Posts: 19
|
|
Hi... I have a FIRSTclass that have many button in the interface, when I click in one button open a small window and into the small window I have a JLabel that set a variable, but the variable is static. In another SECONDclass I have a THREAD that it has that to change the value of the variable, therefore inside of this SECONDclass that has the THREAD I have that adds thus: FirstClass.VARIABLE = "this string dumb of time in time"; Well, when I make my JLabel in FIRSTclass where it has the buttons to receive: JLabel lab = new JLable(VARIABLE); it gives an error of IndexOfBounds being that mine variav�l is a Arrayde 66 positions; I want that when to click in the button, to open the small window with the new value of the variable... Somebody knows what I make?
|
 |
Abhik Sarkar
Ranch Hand
Joined: Jun 14, 2003
Posts: 61
|
|
I am not sure I get your problem, but here is a suggestion anyway... My guess is that VARIABLE is declared as <scope> static String VARIABLE; I would suggest that you try one of these two: <scope> static volatile String VARAIBLE; and leave the rest as it is. or, leave the declaration as it is and: synchronized(VARIABLE) { JLabel lab = new JLable(VARIABLE); } Hope this helps, Abhik.
Originally posted by DanielCosta Sobrinho: Hi... I have a FIRSTclass that have many button in the interface, when I click in one button open a small window and into the small window I have a JLabel that set a variable, but the variable is static. In another SECONDclass I have a THREAD that it has that to change the value of the variable, therefore inside of this SECONDclass that has the THREAD I have that adds thus: FirstClass.VARIABLE = "this string dumb of time in time"; Well, when I make my JLabel in FIRSTclass where it has the buttons to receive: JLabel lab = new JLable(VARIABLE); it gives an error of IndexOfBounds being that mine variav?l is a Arrayde 66 positions; I want that when to click in the button, to open the small window with the new value of the variable... Somebody knows what I make?
|
 |
DanielCosta Sobrinho
Greenhorn
Joined: Jun 06, 2003
Posts: 19
|
|
I dont know why I use VOLATILE... Can you explain???
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
|
Short explanation of the volatile keyword.
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Abhik Sarkar
Ranch Hand
Joined: Jun 14, 2003
Posts: 61
|
|
I am not quite able to reproduce the problem... I am afraid that the only more help I can provide without looking at the problem code is to provide the code I tried to recreate the problem...
|
 |
DanielCosta Sobrinho
Greenhorn
Joined: Jun 06, 2003
Posts: 19
|
|
|
Personal debtor I obtained to decide my problem
|
 |
 |
|
|
subject: Problem whit ActionListener and static variable
|
|
|