goodidea.java

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

JAVA
47
字号
//: GoodIdea.java
// The best way to design classes using the new
// Java 1.1 event model: use an inner class for
// each different event. This maximizes
// flexibility and modularity.
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class GoodIdea extends Frame {
	Button
		b1 = new Button("Button 1"),
		b2 = new Button("Button 2");

	public GoodIdea() {
		setLayout(new FlowLayout());
		b1.addActionListener(new B1L());
		b2.addActionListener(new B2L());
		add(b1);
		add(b2);
	}

	public class B1L implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			System.out.println("Button 1 pressed");
		}
	}
	
	public class B2L implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			System.out.println("Button 2 pressed");
		}
	}
	
	public static void main(String[] args) {
		Frame f = new GoodIdea();
		f.addWindowListener(
		new WindowAdapter() {
			public void windowClosing(WindowEvent e){
				System.out.println("Window Closing");
				System.exit(0);
			}
		});
		f.setSize(300,200);
		f.setVisible(true);
	}
} ///:~

⌨️ 快捷键说明

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