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

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

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

    Vincent.Chan‘s Blog

    常用鏈接

    統計

    積分與排名

    網站

    最新評論

    Java用開源實現系統系統托盤

    網上主要流傳有兩種方式實現系統托盤:
    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

    這兩個都是開源的...可以根據上面的下載.

    相對來說,我更喜歡SysTray for Java,原因很簡單,SysTray for Java實現了我所要的功能而且相對來說比Windows Tray Icon 要簡單.

    使用SysTray是很簡單的.下載下來的文件有個例子Example.java,照著這個實現你所需要的功能應該不算困難.

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

    下面是一個例子程序:

    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;// 默認窗口寬度

    ?static final int INIT_HEIGHT = 244;// 默認窗口高度

    ?private static final String toolTip = "寬帶計費接口";// 提示文字

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

    ?SysTrayMenu menu;// 菜單

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

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

    ?private JLabel statusLabel = new JLabel();// 運行狀態

    ?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("寬帶計費接口");// 標題
    ??setIconImage(new ImageIcon(getClass().getResource("rocket.gif"))
    ????.getImage());// 圖標
    ??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("系統狀態監視");
    ??statusLabel.setBounds(new Rectangle(45, 35, 280, 40));
    ??statusLabel.setToolTipText("當前系統的運行狀態");
    ??statusLabel.setFont(new Font("宋體", 0, 14));

    ??launchButton.setText("啟動");
    ??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);
    ?}

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

    ??SysTrayMenuItem subItem2 = new SysTrayMenuItem("關于", "關于");
    ??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);
    ?}

    ?/**
    ? * 點擊按鈕事件
    ? */
    ?public void actionPerformed(ActionEvent e) {
    ??if (e.getActionCommand().equalsIgnoreCase("退出")) {
    ???System.exit(0);
    ??} else if (e.getActionCommand().equalsIgnoreCase("啟動")) {
    ???// 啟動計費程序

    ??}
    ?}

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

    ?/**
    ? * 左鍵單擊事件
    ? */
    ?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-27 21:59 Vincent.Chen 閱讀(158) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产aⅴ无码专区亚洲av| 亚洲日本va午夜中文字幕久久| 久久精品亚洲综合| 国产免费高清69式视频在线观看| 大胆亚洲人体视频| 日本一区二区三区免费高清在线| 免费日韩在线视频| 免费一级毛suv好看的国产网站 | 亚洲国产综合精品| 久久精品免费一区二区| 精品久久亚洲中文无码| 99在线视频免费观看视频| 亚洲国产精品综合久久20| 永久免费看mv网站入口| 亚洲码和欧洲码一码二码三码| 女人18一级毛片免费观看| 亚洲av无码成人精品国产 | 毛片免费视频播放| 亚洲日本一线产区和二线| 国产公开免费人成视频| v片免费在线观看| 亚洲av丰满熟妇在线播放| 最好看的中文字幕2019免费| 亚洲中文字幕AV在天堂| 国产乱弄免费视频| 福利免费在线观看| 亚洲成A∨人片在线观看无码| 女人被弄到高潮的免费视频| 四虎影视在线看免费观看| 亚洲国产综合专区在线电影| 野花高清在线观看免费完整版中文 | 亚洲AV乱码久久精品蜜桃| 国产电影午夜成年免费视频| 亚洲另类无码专区丝袜| 亚洲综合伊人久久大杳蕉| jjizz全部免费看片| WWW国产亚洲精品久久麻豆| 亚洲精品乱码久久久久久久久久久久 | 伊人久久精品亚洲午夜| 精品福利一区二区三区免费视频| 婷婷国产偷v国产偷v亚洲|