谁有java托盘程序,没有有什么要求的,就是能简单的实现最小化早右下脚,实现数据库的查询就可以了,如果没有实现数据库的查询,那就先求一个最简单的托盘程序!
解决方案 »
- 求问获知socket服务器断开
- 用jsp+Access数据库,但是Resultset的所有方法的返回值都是false是怎么回事啊?
- java nio服务器与多客户端通讯
- 联接Oracle数据库的问题。
- 生成xml文件出现的内存溢出问题。
- 使用JAVA语言 如何将文件从服务器下载入指定的本地文件夹内?(FTP) 急用 在线等
- 【请教】如何用 jdom 生成如下格式的xml ?
- 菜鸟问问
- 你给我答案,我给你分数。
- java ascii 和utf8无BOM的区别怎么判断?
- java session读取对象
- 请教:我在resin下 用jspSmartUpload.jar 进行上传,总是报错?在tomcat下上传都是成功的
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;public class TrayIcon {private PopupMenu popup;
private TrayIcon trayIcon;
private SystemTray tray; public static void main(String[] args) {
TrayIcon trayIconDemo = new TrayIcon();
} public TrayIcon() {
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
popup = new PopupMenu();
trayIcon = new TrayIcon(createImage("1.gif", "tray icon"));
tray = SystemTray.getSystemTray(); CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
MenuItem cb2 = new MenuItem("change Icon");
MenuItem exitItem = new MenuItem("Exit"); popup.add(cb1);
popup.add(cb2);
popup.addSeparator();
popup.add(exitItem); trayIcon.setPopupMenu(popup); try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
return;
} trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"This dialog box is run from System Tray");
}
}); cb1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
int cb1Id = e.getStateChange();
if (cb1Id == ItemEvent.SELECTED){
trayIcon.setImageAutoSize(true);
} else {
trayIcon.setImageAutoSize(false);
}
}
}); cb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trayIcon.setImage(createImage("2.gif", "tray icon"));
}
}); exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tray.remove(trayIcon);
System.exit(0);
}
});
} protected Image createImage(String path, String description) {
URL imageURL = TrayIconDemo.class.getResource(path); if (imageURL == null) {
System.err.println("Resource not found: " + path);
return null;
} else {
return (new ImageIcon(imageURL, description)).getImage();
}
}
}
F:\jdk6.0\bin>javac TrayIcon.java
TrayIcon.java:10: cannot resolve symbol
symbol : class SystemTray
location: class TrayIcon
private SystemTray tray;
^
TrayIcon.java:17: cannot resolve symbol
symbol : variable SystemTray问一下,是什么原因?
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;public class TrayIconDemo {private PopupMenu popup;
private TrayIcon trayIcon;
private SystemTray tray;public static void main(String[] args)
{
TrayIconDemo trayIconDemo = new TrayIconDemo();
}public TrayIconDemo() {
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
popup = new PopupMenu();
trayIcon = new TrayIcon(createImage("1.gif", "tray icon"));
tray = SystemTray.getSystemTray();CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
MenuItem cb2 = new MenuItem("change Icon");
MenuItem exitItem = new MenuItem("Exit");popup.add(cb1);
popup.add(cb2);
popup.addSeparator();
popup.add(exitItem);trayIcon.setPopupMenu(popup);try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
return;
}trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"This dialog box is run from System Tray");
}
});cb1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
int cb1Id = e.getStateChange();
if (cb1Id == ItemEvent.SELECTED){
trayIcon.setImageAutoSize(true);
} else {
trayIcon.setImageAutoSize(false);
}
}
});cb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trayIcon.setImage(createImage("2.gif", "tray icon"));
}
});exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tray.remove(trayIcon);
System.exit(0);
}
});
}protected Image createImage(String path, String description) {
URL imageURL = TrayIconDemo.class.getResource(path);if (imageURL == null) {
System.err.println("Resource not found: " + path);
return null;
} else {
return (new ImageIcon(imageURL, description)).getImage();
}
}
}我运行通过,并且显示出来了,编译运行是要设置你的classpath;
如下:
set classpath=D:\project\Test\src;E:\Program Files\Java\jdk1.6.0_02\lib\tools.jar;