enabletest.java

来自「我在学习JAVA的讲义」· Java 代码 · 共 65 行

JAVA
65
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class EnableTest extends JFrame {
   private JButton button1;
   private JButton button2;
   private JButton button3;
   private JTextField text;
  

   public EnableTest()
   {
      super( "Testing Enable" );
    
      Container c = getContentPane();
      c.setLayout( new FlowLayout() );      

      button1 = new JButton("Enable" );
      button2 = new JButton("Visible" );
      button3 = new JButton("Focus" );
      button1.addActionListener(new ActionListener(){
      	public void actionPerformed(ActionEvent e){
      		text.setEnabled(!text.isEnabled());
      	}
      });
      
      button2.addActionListener(new ActionListener(){
      	public void actionPerformed(ActionEvent e){
      		text.setVisible(!text.isVisible());
      	}
      });

      button3.addActionListener(new ActionListener(){
      	public void actionPerformed(ActionEvent e){
      		text.requestFocus();
      		
      	}
      });

      c.add( button1 );
      c.add( button2 );
      c.add( button3 );

      text = new JTextField( "标签是否可用,可见",30);
      c.add( text );

      setSize( 350, 200 );
      show();
   }

   public static void main( String args[] )
   { 
      EnableTest app = new EnableTest();

      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
      );
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?