button2new.java

来自「翁剀JAVA语言那门课程的教案 很多人都看多他的视频教程可惜没有ppt的教案」· Java 代码 · 共 45 行

JAVA
45
字号
//: Button2New.java
// Capturing button presses
import java.awt.*;
import java.awt.event.*; // Must add this
import java.applet.*;

public class Button2New extends Applet {
	Button
		b1 = new Button("Button 1"),
		b2 = new Button("Button 2");
	public void init() {
		b1.addActionListener(new B1());
		b2.addActionListener(new B2());
		add(b1);
		add(b2);
	}

	class B1 implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			getAppletContext().showStatus("Button 1");
		}
	}
	
	class B2 implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			getAppletContext().showStatus("Button 2");
		}
	}

/* The old way:
	public boolean action(Event evt, Object arg) {
		if(evt.target.equals(b1))
			getAppletContext().showStatus("Button 1");
		else if(evt.target.equals(b2))
			getAppletContext().showStatus("Button 2");
		// Let the base class handle it:
		else
			return super.action(evt, arg);
		return true; // We've handled it here
	}
*/
} ///:~

//	<applet code=Button2New.class width=200 height=200></applet>

⌨️ 快捷键说明

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