监听器

监听器删除当前页面的窗口
TestFrame.this.dispose();

当前页面class .this .dispose()



监听3种实现
package chuangkou;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import lovo.Mytest;
public class TestFrame extends JFrame implements ActionListener {
     private MyTest nameText=new MyTest("姓名",70,50,this);
     public TestFrame(){
          this.setLayout(null);
          
          
          MyButton b=new MyButton("确定", 50, 50, this);
          /*
          b.addActionListener(new MyAction());*/
//        b.addActionListener(this);
          b.addActionListener(new ActionListener() {
              
              @Override
              public void actionPerformed(ActionEvent e) {
                   // TODO Auto-generated method stub
                   String info=nameText.getText();
                   System.out.println(info);
                   
                   
              }
          });
          this.setSize(500,400);
          //可见度
          this.setVisible(true);
          //关闭
          this.setDefaultCloseOperation(3);
          //居中
          this.setLocationRelativeTo(null);
     }
     public static void main(String[] args) {
          TestFrame t=new TestFrame();
     }
     @Override
     public void actionPerformed(ActionEvent e) {
          // TODO Auto-generated method stub
          System.out.println("*********************---");
          
     }
}





//第二种的class
package chuangkou;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MyAction  implements ActionListener{
     @Override
     public void actionPerformed(ActionEvent e) {
          // TODO Auto-generated method stub
          System.out.println("********");
          
     }
}



阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页