⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testaddlistener.java

📁 java的书上例子
💻 JAVA
字号:
//例12_9  给按钮添加监听器
import java.awt.*;
import java.awt.event.*;
public class TestAddListener implements ActionListener,WindowListener{
   Frame f;
   Button b;
  
public void create(){
   f=new Frame("testing");
   b=new Button("press");
   b.addActionListener(this); //为按钮注册ActionListener监听器
   f.addWindowListener(this); //为Frame注册WindowListener监听器
   f.add(b,"North");
   f.setSize(200,200);
   f.setVisible(true);
}

public static void main(String args[]){
    TestAddListener ta=new TestAddListener();
    ta.create();
}

public void actionPerformed(ActionEvent e){
     System.out.println("the Button is pressed"); 
}
public void windowActivated(WindowEvent e){};
public void windowClosed(WindowEvent e){};
public void windowClosing(WindowEvent e){System.exit(1);}; //实现窗口关闭功能
public void windowDeactivated(WindowEvent e){};
public void windowDeiconified(WindowEvent e){};
public void windowIconified(WindowEvent e){};
public void windowOpened(WindowEvent e){};

}

⌨️ 快捷键说明

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