• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem whit ActionListener and static variable

 
DanielCosta Sobrinho
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know why I use VOLATILE...
Can you explain???
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short explanation of the volatile keyword.
 
Abhik Sarkar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personal debtor I obtained to decide my problem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic