简体   繁体   English

Java 桌面应用程序中的会话等效项

[英]Session equivalent in Java Desktop Application

I would like to ask you, i am a PHP developer with some basic knowledge of java.我想问你,我是一名 PHP 开发人员,对 Java 有一些基本的了解。

In PHP we use session to store variables so that it can be used across pages.在 PHP 中,我们使用 session 来存储变量,以便它可以跨页面使用。

Is there a way to store the variables is session (or something similar) so that i could access it through the entire desktop application?有没有办法存储变量是会话(或类似的东西),以便我可以通过整个桌面应用程序访问它?

The easy way: use static variables or Singleton classes.简单的方法:使用静态变量或单例类。

The right way: please study "Object Oriented Programming" and "Design Patterns".正确的方法:请学习“面向对象编程”和“设计模式”。 You will be surprised with the big world that such knowledge can give to you!你会惊讶于这样的知识可以给你带来的大世界!

if you use a button or label or image to go around the desktop application you could give the object a variable as parameter with use of a ActionEvent, sort of looks like:如果您使用按钮或标签或图像来浏览桌面应用程序,您可以使用 ActionEvent 为对象提供一个变量作为参数,看起来像:

   button_next.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
      //Put as many as you need in there
         new TheClassToGoTo(nameofvariable);
      }
   });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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