java中的变量压缩和扩展?

发布于 2024-09-10 23:41:50 字数 267 浏览 4 评论 0原文

当我单击包含信息的标签时,我想创建一系列新窗口。我希望这些窗口成为孤立的。有没有办法将静态变量传递给类并告诉它继续监视该变量的状态?

基本上我想说

    NewOrphanedWindow.main(StaticClass.ValueToMonitorFromNowOn);

有没有办法做到这一点,或者是否必须在另一侧进行编程?

我基本上想要一个窗口,它将接收变量字符串名称,然后使用该变量字符串来引用实际的静态变量。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

纸短情长 2024-09-17 23:41:50

不确定您到底想做什么,但您可以通过在调用 main 之前设置静态变量来实现它:

NewOrphanedWindow.monitor = StaticClass.ValueToMonitorFromNowOn;

Not sure what exactly you are trying to do, but you can achieve it by setting a static variable before calling main:

NewOrphanedWindow.monitor = StaticClass.ValueToMonitorFromNowOn;
栩栩如生 2024-09-17 23:41:50

您可以在窗口类中运行一个线程,该线程每 X 秒检查一次变量的值并做出相应的响应:

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();

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();
℉服软 2024-09-17 23:41:50

查找表是必经之路

Lookup table is the way to go

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文