Jump to content

SystemTrayManager


Botre

Recommended Posts

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
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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