badidea1.java

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

JAVA
57
字号
//: BadIdea1.java
// Some literature recommends this approach,
// but it's missing the point of the new event
// model in Java 1.1
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class BadIdea1 extends Frame
	implements ActionListener, WindowListener {

	Button
		b1 = new Button("Button 1"),
		b2 = new Button("Button 2");

	public BadIdea1() {
		setLayout(new FlowLayout());
		addWindowListener(this);
		b1.addActionListener(this);
		b2.addActionListener(this);
		add(b1);
		add(b2);
	}

	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if(source == b1)
			System.out.println("Button 1 pressed");
		else if(source == b2)
			System.out.println("Button 2 pressed");
		else
			System.out.println("Something else");
	}

	public void windowClosing(WindowEvent e) {
		System.out.println("Window Closing");
		System.exit(0);
	}

	public void windowClosed(WindowEvent e) {}

	public void windowDeiconified(WindowEvent e) {}

	public void windowIconified(WindowEvent e) {}

	public void windowActivated(WindowEvent e) {}

	public void windowDeactivated(WindowEvent e) {}

	public void windowOpened(WindowEvent e) {}

	public static void main(String[] args) {
		Frame f = new BadIdea1();
		f.setSize(300,200);
		f.setVisible(true);
	}
} ///:~

⌨️ 快捷键说明

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