windowtest.java

来自「这是清华大学编写的JAVA教材中所有题目的源代码!」· Java 代码 · 共 44 行

JAVA
44
字号
import java.awt.*;
import java.awt.event.*;

class WindowTest implements ActionListener
{
	Frame f=new Frame("Window示例");
	Window w=new Window(f);
	Label l=new Label("这是一个弹出式Window");
	Button btn1=new Button("弹出Window");
	Button btn2=new Button("结束程序");

	public WindowTest() 
	{
		w.setForeground(Color.white);
		w.setBackground(Color.blue);
		w.add(l);
		w.pack();
		w.setLocation(250,200);
		
		btn1.addActionListener(this);
		btn2.addActionListener(this);

		f.setLayout(new FlowLayout());
		f.add(btn1);
		f.add(btn2);
		f.setSize(200,150);
		f.setVisible(true);		
	}

	public void actionPerformed(ActionEvent e)
	{
		Button b=(Button)e.getSource();
		if(b==btn1)
			w.show();
		else if(b==btn2)
			System.exit(0);	
	}

	public static void main(String args[])
	{
		new WindowTest();
	}
}

⌨️ 快捷键说明

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