asked on
//code snippet for timer
actionlistner t_ac=
t_ac = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// jButton1ActionPerformed(null);
// jButton4ActionPerformed(null);
//t_sendTRD.run();
// t_RecvTRD.run();
formWindowOpened(null);
}
};
m_MainTmr = new Timer(1000, t_ac);
m_MainTmr.start();
//To draw trayIcon
private void DrawTrayIcon() {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("C:\\Documents and Settings\\XML\\Globe.jpg");
final JPopupMenu popup = new JPopupMenu();
JMenuItem item = new JMenuItem("Exit");
JMenuItem ite = new JMenuItem("jjklk");
popup.add(item);
popup.add(ite);
TrayIcon trayIcon = new TrayIcon(image, "Right Click", null);
javax.swing.Action t_acc = new javax.swing.Action() {
public Object getValue(String key) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void putValue(String key, Object value) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void setEnabled(boolean b) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean isEnabled() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equalsIgnoreCase("EXIT")) {
System.exit(0);
}
}
};
ite.addActionListener(t_acc);
item.addActionListener(t_acc);
trayIcon.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
if (e.isPopupTrigger()) {
try {
popup.setLocation(e.getX(), e.getY());
popup.setInvoker(popup);
popup.setVisible(true);
Thread.sleep(MouseEvent.MOUSE_EVENT_MASK);
} catch (InterruptedException ex) {
Logger.getLogger(ApprovalUtility.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
if (e.isPopupTrigger()) {
popup.setLocation(e.getX(), e.getY());
popup.setInvoker(popup);
popup.setVisible(true);
}
}
}
public void mouseEntered(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void mouseExited(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
});
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("Can't add to tray");
}
}