Java 使用什么技术将systray前端写入webapp?
我们有一个运行在tomcat上的内部Web应用程序,构建在Spring上。webapplication前端是使用Flex构建的。Java 使用什么技术将systray前端写入webapp?,java,apache-flex,swing,spring,Java,Apache Flex,Swing,Spring,我们有一个运行在tomcat上的内部Web应用程序,构建在Spring上。webapplication前端是使用Flex构建的。 我想创建一个跨平台的systray应用程序,允许进入应用程序的主页,并在服务器发生某些事件时显示警报 您认为哪种技术最适合: 系统本身?Java Swing 服务器与systray之间的通信?网络服务?RSS源?春季远程教学?JMX通知 问候, Wim使用AdobeAIR和BlazeDS或LCD,您可以轻松构建此类应用程序。我选择FreePascal。它以本机方式
我想创建一个跨平台的systray应用程序,允许进入应用程序的主页,并在服务器发生某些事件时显示警报 您认为哪种技术最适合:
- 系统本身?Java Swing
- 服务器与systray之间的通信?网络服务?RSS源?春季远程教学?JMX通知
Wim使用AdobeAIR和BlazeDS或LCD,您可以轻松构建此类应用程序。我选择FreePascal。它以本机方式编译到windows/mac/linux,因此您不需要依赖任何其他要安装的框架(.net、java、air)。只有一个可执行文件,就是它。我同意:如果你对Flex有投资和专业知识,那么用Air扩展它是有意义的
至于有效负载——如果你只是需要不时地“弹出”通知,RSS就是一种选择。否则,您可以使用自己的XML REST-like服务,因为它很容易设置,并且从长远来看会给您带来灵活性。如果您想继续使用Java,您有两个选择:
- 使用Swing/AWT。确保您使用的是Java 6及以上版本(您可以将其与应用程序一起安装),因为它支持system tray(从API):
- 使用/。以下是一个示例(摘自):
publicstaticvoidmain(字符串[]args){ 显示=新显示(); 外壳=新外壳(显示); 图像=新图像(显示,16,16); 最终托盘=display.getSystemTray(); 如果(托盘==null){ System.out.println(“系统托盘不可用”); }否则{ 最终输送装置项目=新输送装置(塔盘,SWT.无); item.setToolTipText(“SWT传输项”); item.addListener(SWT.Show,newlistener()){ 公共无效handleEvent(事件){ 系统输出打印项次(“显示”); } }); item.addListener(SWT.Hide,new Listener()){ 公共无效handleEvent(事件){ System.out.println(“隐藏”); } }); item.addListener(SWT.Selection,new Listener()){ 公共无效handleEvent(事件){ System.out.println(“选择”); } }); item.addListener(SWT.DefaultSelection,new Listener(){ 公共无效handleEvent(事件){ System.out.println(“默认选择”); } }); 最终菜单=新菜单(外壳,SWT.弹出); 对于(int i=0;i<8;i++){ MenuItem mi=新MenuItem(菜单,SWT.PUSH); mi.setText(“项目”+i); mi.addListener(SWT.Selection,new Listener()){ 公共无效handleEvent(事件){ System.out.println(“选择”+事件小部件); } }); 如果(i==0) menu.setDefaultItem(mi); } item.addListener(SWT.MenuDetect,new Listener()){ 公共无效handleEvent(事件){ menu.setVisible(true); } }); 项目.设置图像(图像); } 壳.立根(50,50,300,200); shell.open(); 而(!shell.isDisposed()){ 如果(!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
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);
}
// ...
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();
}