代码之家  ›  专栏  ›  技术社区  ›  Wim Deblauwe

使用什么技术将Systray前端写入webapp?

  •  2
  • Wim Deblauwe  · 技术社区  · 15 年前

    我们在Tomcat上运行了一个内部Web应用程序,构建在Spring上。WebApplication前端是用flex构建的。
    我想创建一个跨平台的Systray应用程序,它允许进入应用程序的主页,并在服务器中发生某些事情时显示警报。

    您认为哪种技术最适合:

    • 系统本身?爪哇摇摆?
    • 服务器和Systray之间的通信?Webservice?RSS源?弹簧远程处理?JMX通知?

    当做,

    维姆

    4 回复  |  直到 15 年前
        1
  •  3
  •   David Rabinowitz    15 年前

    如果你想继续使用Java,你有两种选择:

    • 使用挥杆/AWT。确保你使用Java 6和以上(你可以用你的应用程序安装它),因为它支持系统托盘(从API):

      TrayIcon trayIcon = null;
      if (SystemTray.isSupported()) {
          // get the SystemTray instance
          SystemTray tray = SystemTray.getSystemTray();
          // load an image
          Image image = Toolkit.getDefaultToolkit.getImage("");
          // create a action listener to listen for default action executed on
          // the tray icon
          ActionListener listener = new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  // execute default action of the application
                  // ...
              }
          };
          // create a popup menu
          PopupMenu popup = new PopupMenu();
          // create menu item for the default action
          MenuItem defaultItem = new MenuItem("");
          defaultItem.addActionListener(listener);
          popup.add(defaultItem);
          // / ... add other items
          // construct a TrayIcon
          trayIcon = new TrayIcon(image, "Tray Demo", popup);
          // set the TrayIcon properties
          trayIcon.addActionListener(listener);
          // ...
          // add the tray image
          try {
              tray.add(trayIcon);
          } catch (AWTException e) {
              System.err.println(e);
          }
          // ...
      } else {
          // disable tray option in your application or
          // perform other actions
          // ...
      }
      // ...
      // some time later
      // the application state has changed - update the image
      if (trayIcon != null) {
          trayIcon.setImage(updatedImage);
      }
      // ...
      
    • 使用 SWT / JFace . 以下是一个例子(摘自 here ):

      public static void main(String[] args) {
          Display display = new Display();
          Shell shell = new Shell(display);
          Image image = new Image(display, 16, 16);
          final Tray tray = display.getSystemTray();
          if (tray == null) {
              System.out.println("The system tray is not available");
          } else {
              final TrayItem item = new TrayItem(tray, SWT.NONE);
              item.setToolTipText("SWT TrayItem");
              item.addListener(SWT.Show, new Listener() {
                  public void handleEvent(Event event) {
                      System.out.println("show");
                  }
              });
              item.addListener(SWT.Hide, new Listener() {
                  public void handleEvent(Event event) {
                      System.out.println("hide");
                  }
              });
              item.addListener(SWT.Selection, new Listener() {
                  public void handleEvent(Event event) {
                      System.out.println("selection");
                  }
              });
              item.addListener(SWT.DefaultSelection, new Listener() {
                  public void handleEvent(Event event) {
                      System.out.println("default selection");
                  }
              });
              final Menu menu = new Menu(shell, SWT.POP_UP);
              for (int i = 0; i < 8; i++) {
                  MenuItem mi = new MenuItem(menu, SWT.PUSH);
                  mi.setText("Item" + i);
                  mi.addListener(SWT.Selection, new Listener() {
                      public void handleEvent(Event event) {
                          System.out.println("selection " + event.widget);
                      }
                  });
                  if (i == 0)
                      menu.setDefaultItem(mi);
              }
              item.addListener(SWT.MenuDetect, new Listener() {
                  public void handleEvent(Event event) {
                      menu.setVisible(true);
                  }
              });
              item.setImage(image);
          }
          shell.setBounds(50, 50, 300, 200);
          shell.open();
          while (!shell.isDisposed()) {
              if (!display.readAndDispatch())
                  display.sleep();
          }
          image.dispose();
          display.dispose();
      }
      
        2
  •  1
  •   James Ward    15 年前

    使用AdobeAir和Blazeds或LCD,您可以轻松构建这类应用程序。

        3
  •  0
  •   Birger    15 年前

    我会选择免费帕斯卡。它本身编译成WINDOWS/MAC/Linux,因此,您不需要安装任何其他框架(.NET、Java、Air)。只有一个可执行文件,就这样。

        4
  •  0
  •   Community Heathro    7 年前

    我同意 James :如果你对flex有投资和诀窍,用空气来扩展它是有意义的。

    至于有效负载——如果您只是需要不时“弹出”通知,那么RSS就是解决问题的方法。否则,您将拥有类似于XML REST的服务,因为它很容易设置,并且从长远来看会给您带来灵活性。

    推荐文章