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

📄 jfc.java

📁 贪食蛇的实现源码
💻 JAVA
字号:
package jawt;
	import java.awt.*;
	import java.awt.event.ActionEvent;
	import java.awt.event.ActionListener;
	import java.awt.event.WindowAdapter;
	import java.awt.event.WindowEvent;
	import javax.swing.*;

	public class JFC  extends JFrame implements ActionListener {
	private JFrame f;
	private JLabel label;
	private JButton but;
	private JButton butt;
	private JButton bu;
	public void go(){
		f=new JFrame("Listener test");
		label=new JLabel("this is a label!!");
		but =new JButton("hello!");
		butt=new JButton("welcome!");
		bu=new JButton("return!");
		getContentPane().setLayout(new BorderLayout());//各组件放置位置不同显示效果不同
		f.setSize(300,200);
		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) {
			JFC l=new JFC();
			l.go();
			}

		

	}


⌨️ 快捷键说明

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