testaddlistener.java

来自「Java 图形界面入门实例」· Java 代码 · 共 36 行

JAVA
36
字号
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);
      f.addWindowListener(this);
      f.add(b,"North");
      f.setSize(200,200);
      f.setVisible(true);
    }
    
    public void actionPerformed(ActionEvent e)
    {
       System.out.println("这个按钮被按下!");
    }
    
    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){};

 }

⌨️ 快捷键说明

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