我看过其他有关此内容的文章,但对此并不太了解。
我制作了一个程序,可以像服务器一样工作,同时捕获屏幕上的不同图片。现在,我希望该程序仅在后台处于活动状态-就像显示在隐藏图标下的程序一样。程序没有直接显示在底部任务栏上。我将其执行到jar文件时是否需要在Java程序中添加一些特定的代码?还是我需要以其他方式创建项目?
我希望这是足够的解释-预先感谢
我从Here得到的东西超级简单。我所做的只是添加点击退出。
代码
public static void main (String [] args) {
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
Image image = Toolkit.getDefaultToolkit().getImage("MY/PATH/TO_IMAGE");
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(image, "MY PROGRAM NAME", popup);
final SystemTray tray = SystemTray.getSystemTray();
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
});
popup.add(exitItem);
trayIcon.setPopupMenu(popup);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
}
}
Run Code Online (Sandbox Code Playgroud)
只需获取任何图像并将其添加到您的资源中或保存图像的任何位置并为其创建路径。
| 归档时间: |
|
| 查看次数: |
3921 次 |
| 最近记录: |