如何在任务栏显示java程序图标

王朝学院·作者佚名  2009-10-30
窄屏简体版  字體: |||超大  

该代码实现了在系统右下角的任务栏中显示程序的图标,并且最小化程序后单击图标可以显示出来这个程序窗口。

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();

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航