GUI:Graphical User Interface 图形用户接口
CLI:Command Uesr Interface 命令行用户接口,比如常见的Dos命令行操作
AWT:Abstract Window ToolKit 抽象窗口工具包
Swing:在AWT的基础上建立的一套图形界面系统
GUI继承关系图
- package Base;
- import java.awt.Button;
- import java.awt.FlowLayout;
- import java.awt.Frame;
- import java.awt.TextArea;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- public class MyWindowDemo
- {
- //定义成员变量
- private Frame f;//窗口
- private TextField tf;//文本行
- private Button zhuandaoButton,exitButton;//按钮
- private TextArea ta;//文本区域
- MyWindowDemo()
- {
- init();
- }
- public void init()
- {
- //顶一个窗口
- f = new Frame("my window");
- //对frame进行基本设置
- //长宽高低
- f.setBounds(300,100,500,300);
- //设置布局管理器
- f.setLayout(new FlowLayout());
- tf=new TextField(50);
- zhuandaoButton = new Button("转到");
- exitButton = new Button("退出");
- ta = new TextArea(10,60);
- //将组建添加到f中
- f.add(tf);
- f.add(zhuandaoButton);
- f.add(exitButton);
- f.add(ta);
- //加载窗体上的事件
- myEvent();
- //显示窗体
- f.setVisible(true);
- }
- private void myEvent()
- {
- //定义事件,点击exitButton,就退出
- exitButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- System.exit(0);
- }
- });
- //点击zhuandaoButton按钮,就会将文本行中的数据添加到文本区域中
- zhuandaoButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- //tf.getText("");
- String text = tf.getText();
- //System.out.println(text);
- ta.append(text);
- ta.append("");
- }
- });
- //关闭事件
- f.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- });
- }
- public static void main(String[] args)
- {
- new MyWindowDemo();
- }
- /*public static void showFrame()
- {
- Frame f = new Frame("对话框");
- f.setBounds(300,200,500,300);
- f.setLayout(new FlowLayout());
- Dialog d = new Dialog(f,true);
- Button button = new Button("转到");
- f.add(d);
- f.add(button);
- f.setVisible(true);
- }
- */
- }