系统托盘

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, "系统信息", "系统探针已经启动");
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值