Java SE6 系统托盘小应用哈
/**
* @(#)MyTray.java
*
*
* @author Xie Xiaojin
* @version 1.00 2009/11/9
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyTray implements ActionListener {
private MenuItem item1;
private MenuItem item2;
private MenuItem item3;
private String tip = "谢小进于\n2009年11月9日\n凌晨2:52";
public MyTray(){
if(SystemTray.isSupported()){
SystemTray tray = SystemTray.getSystemTray();
PopupMenu popup = new PopupMenu();
item1 = new MenuItem("我的菜单");
item2 = new MenuItem("关于");
item3 = new MenuItem("退出");
item2.addActionListener(this);
item3.addActionListener(this);
popup.add(item1);
popup.add(item2);
popup.add(item3);
TrayIcon icon = new TrayIcon(getIcon("rss.png").getImage(), tip, popup);
icon.displayMessage("系统提示", tip, TrayIcon.MessageType.INFO);
try{
tray.add(icon);
} catch(AWTException ex){
System.err.println("无法向这个托盘添加新菜单项");
}
} else{
System.out.println("无法使用系统托盘");
}
}
public static void main(String[] args){
new MyTray();
}
public ImageIcon getIcon(String url){
return new ImageIcon(getClass().getResource(url));
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == item2){
JFrame f = new JFrame("系统托盘");
JLabel label = new JLabel(tip);
f.getContentPane().add(label);
f.setSize(300, 200);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
if(e.getSource() == item3){
System.exit(0);
}
}
}
相关文档:
Java学习从入门到精通
一、 JDK (Java Development Kit)
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......
1. 对于一个static方法而言,无法访问泛型类的类型参数,所以,如果static方法需要使用泛型能力,就必须使其成为泛型方法。
2. 当使用泛型类时,必须在创建对象的时候制定类型参数的值,而是用泛型方法的时候,通常不必指定参数类型,因为编译器会为我们找出具体的类型。这称为类型参数推断。 ......
import java.io.*;
public class FileToFile
{
public static void main(String[] args)
{
File fold = new File("e:\\java\\file.java");//某路径下的文件
String strNewPath = "e:\\java\\new file\\";//新路径
File fnewpath = new File(strNewPath);
......