java - Jframe will not close on "X" -
this code work in every way not close fully, seems hang hit "x" on window. after hit close, if minimize screen , maximize black. way can close exit eclipse, ide.
prior had different , feel. stole code gui, made in netbeans make better hand. figure has "nimbus" , feel, maybe not closing other objects problem?
static clutilcompact app = null; // 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 app, , panels app = new clutilcompact(); // let panels have access app aux.setapp(app); stat.setapp(app); user.setapp(app); auto.setapp(app); app.updateoutput("started"); app.updatestatus("started"); input.setapp(app); try { (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 , display form */ java.awt.eventqueue.invokelater(new runnable() { public void run() { app.setdefaultcloseoperation(exit_on_close); app.setalwaysontop(true); app.setvisible(true); } }); }
class automator run , close
public void run() { try // make global hook { globalscreen.registernativehook(); } catch (nativehookexception ex){theapp.updateoutput("no global keyboard or mouse hook");return;} try // create robot (can simulate user input such mouse , keyboard input) { rob = new robot(); } catch (awtexception e1) {theapp.updateoutput("the robot not created");return;} while(true) {} } public void onclose() { globalscreen.unregisternativehook(); }
edit: little red box in eclipse closes it, still on own not.
set default close action "dispose_on_close" instead of exit_on_close (general tip)
hovercraft full of eels comment quite useful. if have undisposed windows or non-daemon threads, application not terminate
check active frames.. use frame.getframes()
if windows/frames disposed of, debug check non-daemon threads still running
one cruel effective solution system.exit(0)
class should implement windowlistener
// use method public void windowclosed(windowevent e){ system.exit(0); }
Comments
Post a Comment