系统托盘
来源:互联网 发布:收腰羽绒服 知乎 编辑:程序博客网 时间:2024/06/06 08:53
public class UI {
private TrayIcon trayIcon;
public UI(){
this.init();
}
public void mini(){
SystemTray tray = SystemTray.getSystemTray();
try {
tray.add(this.trayIcon);
} catch (AWTException e) {
e.printStackTrace();
}
}
public void init(){
Image image = Toolkit.getDefaultToolkit().getImage(System.getProperty("user.dir")+"/image/logo.png");
String tooltip = "SystemProbe";
PopupMenu popup = new PopupMenu();
MenuItem aboutItem = new MenuItem("About");
Map<TextAttribute,Object> fontmap = new HashMap<TextAttribute,Object>();
fontmap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
Font font = Font.getFont(fontmap);
aboutItem.setFont(font);
aboutItem.addActionListener(new AboutActionListener());
popup.add(aboutItem);
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(new ExitActionListener());
popup.add(exitItem);
trayIcon = new TrayIcon(image,tooltip,popup);
}
public void displayMessage(MessageType type,String title,String message){
TrayIcon.MessageType mt = null;
if(type == MessageType.ERROR){
mt = TrayIcon.MessageType.ERROR;
}else if(type == MessageType.INFO){
mt = TrayIcon.MessageType.INFO;
}else if(type == MessageType.NONE){
mt = TrayIcon.MessageType.NONE;
}else if(type == MessageType.WARNING){
mt = TrayIcon.MessageType.WARNING;
}
trayIcon.displayMessage(title, message, mt);
}
public class ExitActionListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
int result = JOptionPane.showConfirmDialog(null, "Are you sare to exit System?","Are you sare to exit System?",JOptionPane.YES_NO_OPTION);
if(result==JOptionPane.YES_NO_OPTION){
System.exit(0);
}
}
}
public class AboutActionListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "SystemProbe","About SystemProbe",JOptionPane.INFORMATION_MESSAGE);
}
}
public enum MessageType{
ERROR
,INFO
,NONE
,WARNING
,NODISPLAY
}
}
public class Main {
public static void main(String[] args) {
UI ui = new UI();
ui.mini();
ui.displayMessage(MessageType.INFO, "系统信息", "系统探针已经启动");
}
}
- 系统托盘
- 系统托盘
- 系统托盘
- 系统托盘
- 系统托盘
- 系统托盘
- 系统托盘
- 系统托盘程序
- 系统托盘实例
- C#系统托盘
- 系统托盘编程
- 系统托盘功能
- 系统托盘gtk
- 系统托盘编程
- vc 系统托盘
- flex系统托盘
- windows系统托盘
- 系统托盘编程
- 老实把工作做好
- 毕业后拉开大家差距的原因(转载)
- myisam引擎的表锁优化
- 关于monton编码
- c++中char * 和 char []的区别
- 系统托盘
- Windows netstat 查看端口、进程占用
- 算法:快速排序
- 皮肤护理技巧
- 常见的排序算法实现
- 计算机核心期刊排名及投稿信息
- 关于C++的metaprograming
- 写在最后一个暑假里的
- SQL Injection Attacks and Defense