⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jianting.java

📁 贪食蛇的实现源码
💻 JAVA
字号:
package awt;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Jianting extends Frame implements ActionListener {
private Frame f;
private Label label;
private Button but;
private Button butt;
private Button bu;
public void go(){
	f=new Frame("Listener test");
	label=new Label("this is a label!!");
	but =new Button("hello!");
	butt=new Button("welcome!");
	bu=new Button("return!");
	f.setLayout(new BorderLayout());//各组件放置位置不同显示效果不同
	f.setSize(300,300);
	f.add(BorderLayout.SOUTH,label);
	f.add(BorderLayout.CENTER,but);
	f.add(BorderLayout.EAST,butt);
	f.add(BorderLayout.WEST,bu);
	f.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent evt){
				f.setVisible(false);
				f.dispose();
				System.exit(0);
			}
		});
	/*ActionListener m=new ActionListener();//不对,因为ActionListen 是接口,不能直接创建对象,得创建继承了该接口的类的对象m下边的写的才对
	but.addActionListener(m);*/  //这么写不对不知为什么??
    but.addActionListener(this);//this 指谁啊??
    butt.addActionListener(this);
    bu.addActionListener(this);
    f.setVisible(true);
}

public void actionPerformed(ActionEvent evt){
	
	if(evt.getSource()==but)
		label.setText("hello hello!!");
	if(evt.getSource()==butt)
		label.setText("welome welcome!!");
	if(evt.getSource()==bu)
		label.setText("this is a label!!");
	
	}


public static void main(String[] args) {
		Jianting l=new Jianting();
		l.go();
		}

	

}

⌨️ 快捷键说明

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