This code does work in every way but now it does not close fully, it seems to hang as I hit the "X" on the window. After I hit close, if I minimize the screen and then maximize it back up it just black. The only way I can get it to close fully is to exit Eclipse, my IDE.
Prior to this I had a different look and feel. I stole some code for the GUI, I made it in netbeans to make it look better than I could do by hand. So I would figure it has to do with the "nimbus" look and feel, but maybe I am not closing other objects properly an it is now a problem?
static CLUtilCompact app = null; // this
static AuxPPanel aux = null; // JPanel
static StatusPanel stat = null; // JPanel
static UserActPanel user = null; // JPanel
static InputPanel input = null; // JPanel
static Automator auto = null;
//public class Automator extends Thread
// implements NativeMouseInputListener, NativeKeyListener
public CLUtilCompact()
{
aux = new AuxPPanel();
stat = new StatusPanel();
user = new UserActPanel();
auto = new Automator();
input = new InputPanel();
GlobalScreen.getInstance().addNativeKeyListener(auto);
GlobalScreen.getInstance().addNativeMouseListener(auto);
GlobalScreen.getInstance().addNativeMouseMotionListener(auto);
auto.start();
}
public static void main(String[] args)
{
// Create the App, and panels
app = new CLUtilCompact();
// Let the panels have access to app now
aux.setApp(app);
stat.setApp(app);
user.setApp(app);
auto.setApp(app);
app.updateOutput("Started");
app.updateStatus("Started");
input.setApp(app);
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(CLUtilCompact.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CLUtilCompact.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CLUtilCompact.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CLUtilCompact.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
app.setDefaultCloseOperation(EXIT_ON_CLOSE);
app.setAlwaysOnTop(true);
app.setVisible(true);
}
});
}
Class Automator run and close
public void run()
{
try // to make the Global hook
{
GlobalScreen.registerNativeHook();
}
catch (NativeHookException ex){theApp.updateOutput("No Global Keyboard or Mouse Hook");return;}
try // to create a robot (can simulate user input such as mouse and keyboard input)
{
rob = new Robot();
}
catch (AWTException e1) {theApp.updateOutput("The Robot could not be created");return;}
while(true) {}
}
public void OnClose()
{
GlobalScreen.unregisterNativeHook();
}
EDIT: The little red box in eclipse closes it, but still on its own it does not.