Jump to content

SystemTrayManager


Recommended Posts

Posted (edited)

ph34r.png (fetched from an old 2D game API of mine)

package game_context;

import java.awt.AWTException;
import java.awt.SystemTray;
import java.awt.TrayIcon;

/**
 * @author Bjorn Krols (Botre)
 */

public class SystemTrayManager {

	private static SystemTrayManager instance = new SystemTrayManager(); 
	private boolean supported;
	private SystemTray tray;
	
	private SystemTrayManager() {
		supported = SystemTray.isSupported();
		if (!supported) return;
		setTray(SystemTray.getSystemTray());
	}
	
	public static SystemTrayManager getInstance() { return instance == null ? instance = new SystemTrayManager() : instance; }

	private SystemTray getTray() { return supported ? tray : null; }

	private void setTray(SystemTray tray) {
		if (!supported) return;
		this.tray = tray;
	}

	public void setIcon(TrayIcon icon) {
		if (!supported) return;
		try {
			getTray().add(icon);
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}
	
}
Edited by Botre
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...