skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Wednesday, September 19, 2012

Loading in System Tray

Posted by Admin at 7:28 AM – 0 comments
 
This sample code helps the developer to load the java swing application in into the System Tray

The Tray.dll file should be placed either in the application directory or the System32 folder 
import org.jdesktop.jdic.tray.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class TrayClockSample implements ActionListener{

    SystemTray tray = SystemTray.getDefaultSystemTray();


 JDialog jfrTrayAuthor ;

    public TrayClockSample() {

        JPopupMenu menu;
        JMenuItem menuItemShow;
        JMenuItem menuItemAbout;
        JMenuItem menuItemDayLight;
        JMenuItem menuItemQuit;
        JMenuItem menuItemAuthor;
        JMenuItem menuItemUpdate;


        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        menu = new JPopupMenu("A Menu");




  menuItemAuthor = new JMenuItem("Show Tray Sample");
        menuItemAuthor.addActionListener(this);
        menuItemAuthor.setActionCommand("Author");
  menu.add(menuItemAuthor);

        menu.addSeparator();
        menuItemQuit = new JMenuItem("Quit");
        menuItemQuit.addActionListener(this);
        menuItemQuit.setActionCommand("Quit");
        menu.add(menuItemQuit);







  jfrTrayAuthor = new  JDialog();
  jfrTrayAuthor.setTitle("Author ");
  TrayAuthor aa = new TrayAuthor();
  jfrTrayAuthor.getContentPane().add(aa);
  jfrTrayAuthor.setLocation(500,550);
  jfrTrayAuthor.setSize(450,150);





        ImageIcon i = new ImageIcon(TrayClockSample.class.getResource("images/clock.gif"));

        TrayIcon ti = new TrayIcon(i, "Tray sample", menu);

        ti.setIconAutoSize(true);
        ti.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jfrTrayAuthor.setVisible(true);
            }
        });
        tray.addTrayIcon(ti);


    }


    public void actionPerformed(ActionEvent e) {
  if ("Quit".equals(e.getActionCommand()))
             System.exit(0);


   else if("Author".equals(e.getActionCommand()))
   jfrTrayAuthor.setVisible(true);


    }

    public static void main(String[] args) {
        new TrayClockSample();
    }

}

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger