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

📄 awtdemo4.java

📁 JAVA的一些基础教程
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

public class AwtDemo4
{
	public static void main(String arg[])
	{
		Frame win = new Frame("my first GUI application");
		
		Panel p1 = new Panel();
		p1.setLayout(new BorderLayout());
		final TextArea t = new TextArea("textfield");
	
		t.setBackground(Color.red);
		Button b = new Button("ok");

		//用匿名类实现一个对Button的事件处理类对象
		ActionListener action = new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{
				t.append("\nHelloWorld");
			}
		};
		
		//调用Button的方法添加按钮事件处理对象
		b.addActionListener(action);

		//用匿名类实现一个对Button的事件处理类对象
		ActionListener actionClear = new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{
				t.setText("");
			}
		};

		Button c = new Button("clear");

		//调用Button的方法添加按钮事件处理对象
		c.addActionListener(actionClear);

		//用匿名类实现一个对Window窗口的事件处理类对象
		WindowListener l = new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		};

		//添加窗口事件处理代理对象
		win.addWindowListener(l);
		win.add("Center",t);
		win.add("East",b);
		win.add("West",c);
		win.pack();
		win.show();
	}
}

⌨️ 快捷键说明

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