Botre Posted March 8, 2015 Posted March 8, 2015 (edited) (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 March 8, 2015 by Botre
VladBots Posted March 8, 2015 Posted March 8, 2015 (edited) better 2 throw exception if unsupported also why is supported static? Edited March 8, 2015 by VladBots
Botre Posted March 8, 2015 Author Posted March 8, 2015 (edited) better 2 throw exception if unsupported also why is supported static? Making that part throw an exception will make any OS that doesn't support system trays crash :x Mhm not sure, why not though ? Edited March 8, 2015 by Botre
VladBots Posted March 8, 2015 Posted March 8, 2015 Making that part throw an exception will make any OS that doesn't support system trays crash :x Mhm not sure, why not though ? you're not using it statically