如何在任务栏显示java程序图标
2009-10-28 20:58:33 来源:WEB开发网核心提示:该代码实现了在系统右下角的任务栏中显示程序的图标,并且最小化程序后单击图标可以显示出来这个程序窗口,如何在任务栏显示java程序图标, view plaincopy to clipboardPRint?import java.awt.Color; import java.awt.Image; import java.a
该代码实现了在系统右下角的任务栏中显示程序的图标,并且最小化程序后单击图标可以显示出来这个程序窗口。
view plaincopy to clipboardPRint?
import java.awt.Color;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class test extends JFrame
{
long setTime = 30*1000;
JLabel jl = new JLabel("剩余时间:");
JLabel jl1 = new JLabel();
PopupMenu popupMenu1 = new PopupMenu();
MenuItem menuItem1 = new MenuItem();
public examTime(){
this.setLocation(200, 200);
this.setSize(300, 200);
isTray();
this.setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowIconified(WindowEvent evt)
{
unVisible();
}
});
popupMenu1.setLabel("PopupMenu");
menuItem1.setLabel("打开");
menuItem1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
showw();
}
});
popupMenu1.add(menuItem1);
}
public void unVisible(){
this.setVisible(false);
}
public void showw(){
this.setVisible(true);
}
public void isTray()
{
try
{
if (SystemTray.isSupported())
{// 判断当前平台是否支持系统托盘
SystemTray st = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage(
"E:/eclipse/workspace/test/test.gif");//定义托盘图标的图片
TrayIcon ti = new TrayIcon( image);
ti.setToolTip ( "test ");
ti.setPopupMenu ( this.popupMenu1);
st.add(ti);
}
}
catch (Exception e)
{
}
}
public static void main(String[] args)
{
new test();
}
}
view plaincopy to clipboardPRint?
import java.awt.Color;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class test extends JFrame
{
long setTime = 30*1000;
JLabel jl = new JLabel("剩余时间:");
JLabel jl1 = new JLabel();
PopupMenu popupMenu1 = new PopupMenu();
MenuItem menuItem1 = new MenuItem();
public examTime(){
this.setLocation(200, 200);
this.setSize(300, 200);
isTray();
this.setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowIconified(WindowEvent evt)
{
unVisible();
}
});
popupMenu1.setLabel("PopupMenu");
menuItem1.setLabel("打开");
menuItem1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
showw();
}
});
popupMenu1.add(menuItem1);
}
public void unVisible(){
this.setVisible(false);
}
public void showw(){
this.setVisible(true);
}
public void isTray()
{
try
{
if (SystemTray.isSupported())
{// 判断当前平台是否支持系统托盘
SystemTray st = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage(
"E:/eclipse/workspace/test/test.gif");//定义托盘图标的图片
TrayIcon ti = new TrayIcon( image);
ti.setToolTip ( "test ");
ti.setPopupMenu ( this.popupMenu1);
st.add(ti);
}
}
catch (Exception e)
{
}
}
public static void main(String[] args)
{
new test();
}
}
更多精彩
赞助商链接