2011-12-21 12 views
8

क्या दोनों के बीच कोई अंतर है। मैं वर्तमान में मैंSystem.exit (0) बनाम JFrame.EXIT_ON_CLOSE

JFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

का उपयोग लेख है कि एक जावा घुमाओ आवेदन के लिए आप एक श्रोता WindowAdapter और और कॉल जोड़ना चाहिए कहते हैं एक लेख (http://www.javalobby.org/java/forums/t17933) इस बारे में आप हमेशा

System.exit(0); 

का उपयोग करना चाहिए पढ़ रहा था System.exit() अपनी विधि windowClosing(WindowEvent e) के अंदर।

क्या कोई अंतर है? क्या एक तरीका दूसरे के बाद बेहतर है?

उत्तर

12

आप JFrame कोड को देखें, तो यह होता है:

protected void processWindowEvent(WindowEvent e) { 
     super.processWindowEvent(e); 

     if (e.getID() == WindowEvent.WINDOW_CLOSING) { 
      switch(defaultCloseOperation) { 
       ... 
      case EXIT_ON_CLOSE: 
        // This needs to match the checkExit call in 
        // setDefaultCloseOperation 
     System.exit(0); 
     break; 
      } 
     } 
    } 

इसलिए, यह बिल्कुल वही बात है। अगर मैं ऐसा करना चाहता हूं तो मैं बस EXIT_ON_CLOSE सेट करूंगा।

0

ठीक है, System.exit (0) पर विचार करने से JFrame कोडिंग में है, या तो काम करेगा।

संबंधित मुद्दे