windowlistenertest2.java

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

JAVA
55
字号
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class quitwindowCh15_13 extends Frame implements ActionListener
{
	TextArea text;
	Button btn;
	quitwindowCh15_13(String s)
	{ 
		super("我可以工作了");
		text=new TextArea(10,10);
		text.setBackground(Color.cyan);
		btn=new Button("确定");
		btn.addActionListener(this);
		setLayout(new BorderLayout());
		setSize(80, 80);
		setVisible(true);
		add(text,"Center");
		add("South",btn);
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				setVisible(false);
				System.exit(0);
			}
		});
	}

	public void actionPerformed(ActionEvent e)//实现接口中的方法。
	{
		String s;
		if(e.getSource()==btn)
		{ 
			text.setText("ok");
		}
	}
}

public class WindowListenerTest2
{
	/*
	quitwindowCh15_13 myWindow;
	public void init()
	{
		myWindow=new quitwindowCh15_13("法制之窗");
	}
	*/
	public static void main(String args[])
	{
		quitwindowCh15_13 myWindow;
		myWindow=new quitwindowCh15_13("法制之窗");
	}
}

⌨️ 快捷键说明

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