Purpose:Making a tray system for your client.
Difficulty:1/10.
Assumed Knowledge: C&P.
Classes Modified: Gui.java, JFrame.java.
Refactored/Non-Refactored?: Refactored but work on all clients
Step 1 :
Open your Gui.java or JFrame.java and add this method
Code:
public void setTray() {
boolean showTip = false;
if (tray == null) {
showTip = true;
final Image image = Toolkit.getDefaultToolkit().getImage(
"/icon.png");// change the image location
tray = new TrayIcon(image, "Client Title", null);
tray.setImageAutoSize(true);
tray.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mouseReleased(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
SystemTray.getSystemTray().remove(tray);
frame.setVisible(true);
}
});
}
try {
SystemTray.getSystemTray().add(tray);
if (showTip) {
tray.displayMessage(
"Tray icon message title",
"Anything you want use "\n" to break a line.",
MessageType.INFO);
}
} catch (Exception ignored) {
}
frame.setVisible(false);
}
Step 2:
use setTray(); to call that method, you can make a JButton hides your client or if you want to make it hide it self on windows minimize you have to use WindowListener.
Thanks.