<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 20  文章 - 12  trackbacks - 0
    <2006年3月>
    2627281234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    常用鏈接

    留言簿(1)

    隨筆檔案(20)

    java論壇

    我的朋友

    最新隨筆

    搜索

    •  

    積分與排名

    • 積分 - 15081
    • 排名 - 2000

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    網(wǎng)上主要流傳有兩種方式實(shí)現(xiàn)系統(tǒng)托盤:
    1.Windows Tray Icon (http://jeans.studentenweb.org/java/trayicon/trayicon.html)
    shot-balloon.gif

    2.SysTray for Java (http://systray.sourceforge.net/)
    shot.png

    這兩個(gè)都是開源的...可以根據(jù)上面的下載.

    相對(duì)來說,我更喜歡SysTray for Java,原因很簡(jiǎn)單,SysTray for Java實(shí)現(xiàn)了我所要的功能而且相對(duì)來說比Windows Tray Icon 要簡(jiǎn)單.

    使用SysTray是很簡(jiǎn)單的.下載下來的文件有個(gè)例子Example.java,照著這個(gè)實(shí)現(xiàn)你所需要的功能應(yīng)該不算困難.

    主要是菜單和按鈕的操作,和操作一般的JFrame一樣.

    下面是一個(gè)例子程序:

    package qiya.systray;

    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Rectangle;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;

    import snoozesoft.systray4j.SysTrayMenu;
    import snoozesoft.systray4j.SysTrayMenuEvent;
    import snoozesoft.systray4j.SysTrayMenuIcon;
    import snoozesoft.systray4j.SysTrayMenuItem;
    import snoozesoft.systray4j.SysTrayMenuListener;

    public class MainFrame extends JFrame implements ActionListener,
    ??SysTrayMenuListener {

    ?static final int INIT_WIDTH = 400;// 默認(rèn)窗口寬度

    ?static final int INIT_HEIGHT = 244;// 默認(rèn)窗口高度

    ?private static final String toolTip = "寬帶計(jì)費(fèi)接口";// 提示文字

    ?static final SysTrayMenuIcon icon = new SysTrayMenuIcon("rocket.gif");// 圖片信息

    ?SysTrayMenu menu;// 菜單

    ?private JButton launchButton = new JButton();// 啟動(dòng)按鈕

    ?private JButton exitButton = new JButton();// 退出按鈕

    ?private JLabel statusLabel = new JLabel();// 運(yùn)行狀態(tài)

    ?public static void main(String[] args) {
    ??try {
    ???UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    ??} catch (ClassNotFoundException e) {
    ???e.printStackTrace();
    ??} catch (InstantiationException e) {
    ???e.printStackTrace();
    ??} catch (IllegalAccessException e) {
    ???e.printStackTrace();
    ??} catch (UnsupportedLookAndFeelException e) {
    ???e.printStackTrace();
    ??}

    ??new MainFrame();
    ?}

    ?public MainFrame() {
    ??super("寬帶計(jì)費(fèi)接口");// 標(biāo)題
    ??setIconImage(new ImageIcon(getClass().getResource("rocket.gif"))
    ????.getImage());// 圖標(biāo)
    ??this.setLayout(null);
    ??this.setSize(new Dimension(INIT_WIDTH, INIT_HEIGHT));
    ??Dimension dimScreen = Toolkit.getDefaultToolkit().getScreenSize();
    ??int xPos = (dimScreen.width - INIT_WIDTH) / 2;
    ??int yPos = (dimScreen.height - INIT_HEIGHT) / 2;

    ??statusLabel.setText("系統(tǒng)狀態(tài)監(jiān)視");
    ??statusLabel.setBounds(new Rectangle(45, 35, 280, 40));
    ??statusLabel.setToolTipText("當(dāng)前系統(tǒng)的運(yùn)行狀態(tài)");
    ??statusLabel.setFont(new Font("宋體", 0, 14));

    ??launchButton.setText("啟動(dòng)");
    ??launchButton.setBounds(new Rectangle(80, 180, 80, 23));

    ??exitButton.setText("退出");
    ??exitButton.setBounds(new Rectangle(230, 180, 80, 23));

    ??this.getContentPane().add(statusLabel, null);
    ??this.getContentPane().add(launchButton, null);
    ??this.getContentPane().add(exitButton, null);

    ??launchButton.addActionListener(this);
    ??exitButton.addActionListener(this);

    ??this.setBounds(xPos, yPos, INIT_WIDTH, INIT_HEIGHT);

    ??icon.addSysTrayMenuListener(this);
    ??this.createMenu();
    ??this.setVisible(true);
    ?}

    ?/**
    ? * 創(chuàng)建菜單
    ? *
    ? */
    ?private void createMenu() {
    ??SysTrayMenuItem subItem1 = new SysTrayMenuItem("退出", "退出");
    ??subItem1.addSysTrayMenuListener(this);

    ??SysTrayMenuItem subItem2 = new SysTrayMenuItem("關(guān)于", "關(guān)于");
    ??subItem2.addSysTrayMenuListener(this);

    ??SysTrayMenuItem subItem3 = new SysTrayMenuItem("幫助", "幫助");
    ??subItem3.addSysTrayMenuListener(this);

    ??menu = new SysTrayMenu(icon, toolTip);// 生成菜單
    ??menu.addItem(subItem1);
    ??menu.addSeparator();
    ??menu.addItem(subItem2);
    ??menu.addItem(subItem3);
    ?}

    ?/**
    ? * 點(diǎn)擊按鈕事件
    ? */
    ?public void actionPerformed(ActionEvent e) {
    ??if (e.getActionCommand().equalsIgnoreCase("退出")) {
    ???System.exit(0);
    ??} else if (e.getActionCommand().equalsIgnoreCase("啟動(dòng)")) {
    ???// 啟動(dòng)計(jì)費(fèi)程序

    ??}
    ?}

    ?/**
    ? * 菜單選擇事件
    ? */
    ?public void menuItemSelected(SysTrayMenuEvent e) {
    ??if (e.getActionCommand().equalsIgnoreCase("退出")) {
    ???System.exit(0);
    ??} else if (e.getActionCommand().equalsIgnoreCase("關(guān)于")) {
    ???JOptionPane.showMessageDialog(this, "寬帶計(jì)費(fèi)接口" + "完成于2005-3-27");
    ??} else if (e.getActionCommand().equalsIgnoreCase("幫助")) {
    ???JOptionPane.showMessageDialog(this, "寬帶計(jì)費(fèi)接口" + "幫助文件待寫...");
    ??}
    ?}

    ?/**
    ? * 左鍵單擊事件
    ? */
    ?public void iconLeftClicked(SysTrayMenuEvent e) {
    ??if (this.isVisible()) {// 如果可見,最小化
    ???this.setVisible(false);
    ??} else {// 如果不可見顯示出來
    ???this.setVisible(true);
    ??}
    ?}

    ?/**
    ? * 左鍵雙擊事件
    ? */
    ?public void iconLeftDoubleClicked(SysTrayMenuEvent e) {
    ??if (this.isVisible()) {// 如果可見,最小化
    ???this.setVisible(false);
    ??} else {// 如果不可見顯示出來
    ???this.setVisible(true);
    ??}
    ?}
    }


    tray.gif
    posted on 2006-03-28 12:39 閱讀(235) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 羞羞视频免费观看| 亚洲免费视频网址| 老司机午夜在线视频免费| 曰批视频免费30分钟成人| 亚洲国产成人久久综合一| 久久国产乱子伦精品免费强| 亚洲中文字幕久久精品无码APP | 亚洲2022国产成人精品无码区| jizz18免费视频| 国产精品亚洲综合专区片高清久久久| 亚美影视免费在线观看| 精品亚洲一区二区| 最近免费中文字幕大全免费| 亚洲av日韩av无码av| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 久久久无码精品亚洲日韩蜜桃| 中文字幕无码毛片免费看| 久久精品国产亚洲AV麻豆不卡| 日韩精品无码免费一区二区三区| 亚洲最大中文字幕| 日本免费一本天堂在线| 国产成人无码免费网站| 亚洲国产天堂久久综合网站| 永久看日本大片免费35分钟| 亚洲欧美日韩国产精品一区| 亚洲成AⅤ人影院在线观看| 在线看片免费人成视频播| 亚洲国产精品一区二区久| 国产成人免费手机在线观看视频 | 亚洲AV成人影视在线观看 | 国产91免费视频| jizzjizz亚洲日本少妇| 亚洲日韩欧洲乱码AV夜夜摸| 91九色老熟女免费资源站| 亚洲欧美成人av在线观看| 亚洲午夜福利精品久久| 在线看免费观看AV深夜影院| 国产亚洲福利一区二区免费看| 亚洲成Av人片乱码色午夜| 一区二区无码免费视频网站| eeuss草民免费|