we have an internal webapplication running on tomcat, build on Spring. The webapplication front-end is build with Flex.
I would like to create a cross-platform systray application that allows to go the home page of the application and displays alerts when certain things happen in the server.
我们有一个在tomcat上运行的内部web应用程序,基于Spring构建。 Web应用程序前端是使用Flex构建的。我想创建一个跨平台的系统托盘应用程序,它允许进入应用程序的主页,并在服务器中发生某些事情时显示警报。
What would you think is the best technology for:
你认为最好的技术是什么:
- The systray itself? Java Swing?
- Communication between the server and the systray? Webservice? RSS feed? Spring remoting? JMX Notifications?
系统托盘本身? Java Swing?
服务器和系统之间的通信?网络服务? RSS订阅? Spring remoting? JMX通知?
regards,
Wim
4 个解决方案
#1
If you want to stay with Java you have two options:
如果您想继续使用Java,您有两种选择:
-
Use Swing/AWT. Make sure you are using Java 6 and above (you can install it with your application), since it has support for system tray (from the API):
使用Swing / 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); } // ...
-
Use SWT/JFace. Here is an example (taken from here):
使用SWT / JFace。这是一个例子(取自这里):
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
With Adobe AIR and BlazeDS or LCDS you can easily build this type of application.
使用Adobe AIR和BlazeDS或LCDS,您可以轻松构建此类应用程序。
#3
I would go for FreePascal. It compiles natively to windows / mac / linux and because of this you do not depend on any other framework (.net, java, air) to be installed. Just one single executable and that's it.
我会去FreePascal。它本身编译为windows / mac / linux,因此你不依赖于任何其他框架(.net,java,air)来安装。只有一个可执行文件,就是这样。
#4
I agree with James: if you have an investment and know-how in Flex, it makes sense to extend that with Air.
我同意James的观点:如果你在Flex中有投资和技术诀窍,那么将它扩展到Air是有意义的。
As for the payload - if you simply need to 'pop up' notifications from time to time, RSS is the way to go. Otherwise, roll you own XML REST-like service, since it's easy to set up and will give you flexibility in the long run.
至于有效载荷 - 如果您只是需要不时“弹出”通知,RSS就是要走的路。否则,请使用类似XML REST的服务,因为它易于设置,从长远来看,它将为您提供灵活性。
#1
If you want to stay with Java you have two options:
如果您想继续使用Java,您有两种选择:
-
Use Swing/AWT. Make sure you are using Java 6 and above (you can install it with your application), since it has support for system tray (from the API):
使用Swing / 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); } // ...
-
Use SWT/JFace. Here is an example (taken from here):
使用SWT / JFace。这是一个例子(取自这里):
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
With Adobe AIR and BlazeDS or LCDS you can easily build this type of application.
使用Adobe AIR和BlazeDS或LCDS,您可以轻松构建此类应用程序。
#3
I would go for FreePascal. It compiles natively to windows / mac / linux and because of this you do not depend on any other framework (.net, java, air) to be installed. Just one single executable and that's it.
我会去FreePascal。它本身编译为windows / mac / linux,因此你不依赖于任何其他框架(.net,java,air)来安装。只有一个可执行文件,就是这样。
#4
I agree with James: if you have an investment and know-how in Flex, it makes sense to extend that with Air.
我同意James的观点:如果你在Flex中有投资和技术诀窍,那么将它扩展到Air是有意义的。
As for the payload - if you simply need to 'pop up' notifications from time to time, RSS is the way to go. Otherwise, roll you own XML REST-like service, since it's easy to set up and will give you flexibility in the long run.
至于有效载荷 - 如果您只是需要不时“弹出”通知,RSS就是要走的路。否则,请使用类似XML REST的服务,因为它易于设置,从长远来看,它将为您提供灵活性。