Botre Posted March 8, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
VladBots Posted March 8, 2015 Share Posted March 8, 2015 (edited) better 2 throw exception if unsupported also why is supported static? Edited March 8, 2015 by VladBots Quote Link to comment Share on other sites More sharing options...
Botre Posted March 8, 2015 Author Share 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 Quote Link to comment Share on other sites More sharing options...
VladBots Posted March 8, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
Botre Posted March 8, 2015 Author Share Posted March 8, 2015 you're not using it statically Derped. 1 Quote Link to comment Share on other sites More sharing options...
rokx Posted March 8, 2015 Share Posted March 8, 2015 Quote Link to comment Share on other sites More sharing options...
Umz Posted March 23, 2015 Share Posted March 23, 2015 Quote Link to comment Share on other sites More sharing options...