kooyee ‘s blog

          開源軟件, 眾人努力的結晶, 全人類的共同財富
          posts - 103, comments - 55, trackbacks - 0, articles - 66
             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          按鍵退出applet or frame

          Posted on 2008-02-16 23:12 kooyee 閱讀(325) 評論(0)  編輯  收藏 所屬分類: Swing/Applet
          exit = new javax.swing.JButton();
           

           
          exit.addActionListener(
          new java.awt.event.ActionListener() {
                
          public void actionPerformed(java.awt.event.ActionEvent evt) {
                       exitActionPerformed(evt);
                  }

          }
          );
           

           
          private void exitActionPerformed(java.awt.event.ActionEvent evt) {
                  
          try {  
                           System.exit(
          0);
               }
           catch (Exception e){
                      input.setText(
          "Error: " + e.toString());
                  }

              }


          對于frame除了這個方法外 還可以用dispose()
          btnClose.addActionListener( 
                   
                                  
          new ActionListener() 
                                 
          {
                                         
          // pass query to tthe frame
                                       public void actionPerformed( ActionEvent event )
                                       
          {
                           
                                           dispose();
                           
                                       }
           // end actionPerformed
                                   }
            // end ActionListener inner class          
                                ); // end call to addActionListener 
          主站蜘蛛池模板: 韶关市| 苏尼特左旗| 龙里县| 霸州市| 西乌珠穆沁旗| 溆浦县| 长治县| 长武县| 明水县| 涪陵区| 台北市| 沾化县| 阆中市| 疏勒县| 多伦县| 青川县| 隆回县| 屏东市| 汕尾市| 长治市| 商洛市| 蕉岭县| 靖边县| 大关县| 卫辉市| 政和县| 扶沟县| 泉州市| 西城区| 海南省| 滁州市| 纳雍县| 嵩明县| 西华县| 盐源县| 牙克石市| 天长市| 彭州市| 沾益县| 泽普县| 施甸县|