March 8, 201510 yr (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, 201510 yr by Botre
March 8, 201510 yr better 2 throw exception if unsupported also why is supported static? Edited March 8, 201510 yr by VladBots
March 8, 201510 yr Author 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, 201510 yr by Botre
March 8, 201510 yr 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
Create an account or sign in to comment