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 
          主站蜘蛛池模板: 隆回县| 当雄县| 兰溪市| 罗定市| 平和县| 深州市| 麻江县| 彭泽县| 田林县| 仁寿县| 岢岚县| 阿城市| 海丰县| 蒙山县| 钟祥市| 乐陵市| 长垣县| 会昌县| 明光市| 大同县| 泾川县| 内黄县| 建昌县| 黑水县| 建湖县| 丹寨县| 朝阳市| 济源市| 福州市| 厦门市| 蓬安县| 博客| 郁南县| 北川| 晋中市| 友谊县| 博兴县| 沾化县| 靖西县| 封开县| 三穗县|