我想让项目运行时,显示窗体,点击关闭后让项目在后台运行(因为有一些必要的程序总是在运行),同时让窗体消失;等过一段时间后,想在次显示刚才的那个窗体,不知道能实现此过程么?知道的告诉小弟一下
解决方案 »
- java 线程唤醒机制的疑问
- &&问个 线程问题
- 请问如下的多线程代码为何出现异常?
- 请教:使用了System.gc()是否一定会调用 finalize()方法?
- drag and drop
- 当我object[][]数据变化的时候怎样才能及时更新jtable里的数据
- jsp编译错误。。。。请高人指教(在线等待)
- 如何抛出event???????????
- tomcat的JDBC Data Sources问题???????????
- 如何判断是get请求和是post请求?
- EJB java.rmi.NoSuchObjectException: no such object in table
- Eclipse的快捷方式后面加 -clean是什么意思
窗体之间要持有对方窗体的引用.
大概要用到:
java.awt.SystemTray.add(TrayIcon icon);
java.awt.TrayIcon.addActionListener(ActionListener listener);javax.swing.JFrame.setVisible(true);
javax.swing.JFrame.dispose();
jframe.setVisible(true); 显示
jframe.setVisible(false); 关闭设置自定义 点击关闭按钮事件
jframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
为窗口添加点击关闭按钮时的事件:jframe.addWindowListener(new WindowListener(){ @Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
} @Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
} @Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
} @Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
} @Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
} @Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
} @Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
});
if (SystemTray.isSupported()) {
// get the SystemTray instance
SystemTray tray = SystemTray.getSystemTray();
// load an image
Image image = Toolkit.getDefaultToolkit.getImage(...);
// create a action listener to listen for default action executed on the tray icon
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// execute default action of the application
// ...
}
};
// create a popup menu
PopupMenu popup = new PopupMenu();
// create menu item for the default action
MenuItem defaultItem = new MenuItem(...);
defaultItem.addActionListener(listener);
popup.add(defaultItem);
/// ... add other items
// construct a TrayIcon
trayIcon = new TrayIcon(image, "Tray Demo", popup);
// set the TrayIcon properties
trayIcon.addActionListener(listener);
// ...
// add the tray image
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
}
// ...
} else {
// disable tray option in your application or
// perform other actions
...
}
// ...
// some time later
// the application state has changed - update the image
if (trayIcon != null) {
trayIcon.setImage(updatedImage);
}
// ...
TrayIcon什么的。