Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem whit ActionListener and static variable

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know why I use VOLATILE...
Can you explain???
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short explanation of the volatile keyword.
 
Abhik Sarkar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personal debtor I obtained to decide my problem
 
It means our mission is in jeapordy! Quick, read this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic