简体   繁体   中英

variable compression and expansion in java?

I would like to create a series of new windows when I click labels containing information. I want these windows to be orphaned. Is there a way to pass a static variable to a class and tell it to keep monitoring the status of that variable?

Basically I want to say

    NewOrphanedWindow.main(StaticClass.ValueToMonitorFromNowOn);

Is there a way to do this, or does it have to be programmed on the other side?

I basically want a window that will receive a variable String name and then use that variable String to reference the actual static variable.

You could run a thread in your window class which checks the value of the variable every X seconds and responds accordingly:

Thread monitor = new Thread(){
  public void run(){
    while(true){
      //check the value of StaticClass.ValueToMonitorFromNowOn
      try{
        Thread.sleep(1000); //sleep 1 sec
      } catch (InterruptedException e){
        break;
      }
    }
  }
}
monitor.start();

不确定要执行的操作是什么,但是可以通过在调用main之前设置一个静态变量来实现它:

NewOrphanedWindow.monitor = StaticClass.ValueToMonitorFromNowOn;

查找表是必经之路

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM