awteventtestanonymous.java

来自「samplecode 111 for J2SE project」· Java 代码 · 共 53 行

JAVA
53
字号
package soe;import java.awt.Button;import java.awt.Frame;import java.awt.GridLayout;import java.awt.Label;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class AWTEventTestAnonymous extends Frame {/**	 * 	 */	private static final long serialVersionUID = 1L;/*** Event program of AWT using anonymous class	*/	Button button;	Label label;	public AWTEventTestAnonymous() {	super("AWTEventTest");	// setSize(200, 200);	setLayout(new GridLayout(2, 1));	// Create button	button = new Button("Click here");	add(button);	// Create label	label = new Label("");	label.setAlignment(Label.CENTER);	add(label);	// Register action listener using anonymous class	button.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent evt) {	label.setText("Hello, My only one plant,vine ");	pack();	}	});	addWindowListener(new WindowAdapter() {	public void windowClosing(WindowEvent e) {	System.exit(0);	}	});	// set the preferred size	pack();	// show the window	//show(); // Java1.4	setVisible(true); // Java1.5	}	public static void main(String[] args) {	new AWTEventTestAnonymous();	}	}

⌨️ 快捷键说明

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