ch9ex_2.java

来自「java练习程序」· Java 代码 · 共 58 行

JAVA
58
字号
//import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
public class ch9Ex extends Applet
{
  static Button tom,jerry;
  static TextField text;
  {
  	Frame f=new Frame("OK");
  	f.setSize(200,200);
  	f.setVisible(true);
  	Dog hans=new Dog();
  	tom=new Button("tom");
  	jerry=new Button("jerry");
  	text=new TextField(10);
  	tom.addActionListener(hans);
  	f.add(tom,"North");
  	f.add(jerry,"South");
  	f.add(text,"Center");
  	f.pack();
  }
}
*/
public class ch9Ex_2
{
  static Button tom,jerry;
  static TextField text;
  public static void main(String args[])
  {
  	Frame f=new Frame("OK");
  	f.setSize(200,200);
  	f.setVisible(true);
  	Dog hans=new Dog();
  	tom=new Button("tom");
  	jerry=new Button("jerry");
  	text=new TextField(10);
  	tom.addActionListener(hans);
  	f.add(tom,"North");
  	f.add(jerry,"South");
  	f.add(text,"Center");
  	f.pack();
  }
}

class Dog implements ActionListener
{
	ch9Ex boy=new ch9Ex();
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==boy.tom)
		{
			boy.jerry.setLabel("I love the game!");
			boy.text.setText("you are welcom!");
		}
  	}	
}

⌨️ 快捷键说明

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