按键退出applet or frame

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 

你可能感兴趣的:(按键退出applet or frame)