testactionlistenerr.java

来自「JAVA的例子程序」· Java 代码 · 共 28 行

JAVA
28
字号
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class testActionListenerr extends JFrame{
	private JPanel jpanel1;
	private JButton jb1=new JButton("按钮");
	public testActionListenerr(){
		super("testActionListener");
		setSize(300,100);
		jpanel1=new JPanel();
		jpanel1.add(jb1);
		jb1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				log("按钮被操作....");
				log("命令字符串:"+e.getActionCommand());
				log("事件发生时间:"+e.getWhen());
				}
			});
		this.setContentPane(jpanel1);
		}
    public void log(String strInfo){
    	System.out.println(strInfo);
    	}
    public static void main(String agg[]){
    	testActionListenerr ta1=new testActionListenerr();
    	ta1.show();
    	}
	}

⌨️ 快捷键说明

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