public XbpadFrame(final XbpadLogic logic, final Image image) {
		
		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		
		this.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent windowEvent) {
			    setExtendedState(Frame.ICONIFIED); 
			    }
			});
		
		if (SystemTray.isSupported()) {
	        System.out.println("system tray supported");
	        tray = SystemTray.getSystemTray();
	        
	        ActionListener exitListener = new ActionListener() {

	            @Override
				public void actionPerformed(ActionEvent e) {
	                System.out.println("Exiting....");
	                logic.clean();
	                System.exit(0);
	            }
	        };
	        PopupMenu popup = new PopupMenu();
	        MenuItem defaultItem = new MenuItem("Xbpad - Exit");
	        defaultItem.addActionListener(exitListener);
	        popup.add(defaultItem);
	        defaultItem = new MenuItem("Xbpad - Open window");
	        defaultItem.addActionListener(new ActionListener() {

	            @Override
				public void actionPerformed(ActionEvent e) {
	                setVisible(true);
	                setExtendedState(Frame.NORMAL);
	            }
	        });
	        popup.add(defaultItem);
	        trayIcon = new TrayIcon(image, "Xbpad Tray", popup);
	        trayIcon.setImageAutoSize(true);
	    }
	    addWindowStateListener(new WindowStateListener() {

	        @Override
			public void windowStateChanged(WindowEvent e) {
	            if (e.getNewState() == ICONIFIED) {
	                try {
	                    tray.add(trayIcon);
	                    setVisible(false);
	                    System.out.println("added to SystemTray");
	                } catch (AWTException ex) {
	                    System.out.println("unable to add to tray");
	                }
	            }
	            if(e.getNewState() == WindowEvent.WINDOW_CLOSING){
	               try {
	                    tray.add(trayIcon);
	                    setVisible(false);
	                    System.out.println("added to SystemTray");
	                } catch (AWTException ex) {
	                    System.out.println("unable to add to system tray");
	                }
	            }
	            if (e.getNewState() == 7) {
	                try {
	                    tray.add(trayIcon);
	                    setVisible(false);
	                    System.out.println("added to SystemTray");
	                } catch (AWTException ex) {
	                    System.out.println("unable to add to system tray");
	                }
	            }
	            if (e.getNewState() == MAXIMIZED_BOTH) {
	                tray.remove(trayIcon);
	                setVisible(true);
	                System.out.println("Tray icon removed");
	            }
	            if (e.getNewState() == NORMAL) {
	                tray.remove(trayIcon);
	                setVisible(true);
	                System.out.println("Tray icon removed");
	            }
	        }
	    });
	}