这段代码在各个方面都有效,但现在它没有完全关闭,当我点击窗口上的“X”时它似乎挂起。在我关闭后,如果我最小化屏幕然后最大化它,它就会变成黑色。我可以让它完全关闭的唯一方法是退出 Eclipse,我的 IDE。
在此之前,我有不同的外观和感觉。我偷了一些 GUI 代码,我在 netbeans 中制作它,让它看起来比我手工制作的更好。所以我认为它与“nimbus”的外观和感觉有关,但也许我没有正确关闭其他对象,现在这是一个问题?
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);
}
});
}
类 Automator 运行和关闭
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();
}
编辑:日食中的小红框将其关闭,但它仍然没有。