黑马程序员—GUI

来源:互联网 发布:wang域名可以备案吗 编辑:程序博客网 时间:2024/05/16 12:42

GUI:Graphical User Interface 图形用户接口

CLI:Command Uesr Interface 命令行用户接口,比如常见的Dos命令行操作

AWT:Abstract Window ToolKit  抽象窗口工具包

Swing:在AWT的基础上建立的一套图形界面系统

GUI继承关系图

[html] view plaincopy
  1. package Base;  
  2.   
  3. import java.awt.Button;  
  4. import java.awt.FlowLayout;  
  5. import java.awt.Frame;  
  6. import java.awt.TextArea;  
  7. import java.awt.TextField;  
  8. import java.awt.event.ActionEvent;  
  9. import java.awt.event.ActionListener;  
  10. import java.awt.event.WindowAdapter;  
  11. import java.awt.event.WindowEvent;  
  12.   
  13.   
  14.   
  15. public class MyWindowDemo   
  16. {  
  17.     //定义成员变量  
  18.     private Frame f;//窗口  
  19.     private TextField tf;//文本行  
  20.     private Button zhuandaoButton,exitButton;//按钮  
  21.     private TextArea ta;//文本区域  
  22.   
  23.     MyWindowDemo()  
  24.     {  
  25.         init();  
  26.     }  
  27.   
  28.     public void init()  
  29.     {  
  30.         //顶一个窗口  
  31.         f = new Frame("my window");  
  32.   
  33.         //对frame进行基本设置  
  34.         //长宽高低  
  35.         f.setBounds(300,100,500,300);  
  36.         //设置布局管理器  
  37.         f.setLayout(new FlowLayout());  
  38.           
  39.         tf=new TextField(50);  
  40.   
  41.         zhuandaoButton = new Button("转到");  
  42.         exitButton = new Button("退出");  
  43.           
  44.         ta = new TextArea(10,60);  
  45.   
  46.         //将组建添加到f中  
  47.         f.add(tf);  
  48.         f.add(zhuandaoButton);  
  49.         f.add(exitButton);  
  50.         f.add(ta);  
  51.   
  52.         //加载窗体上的事件  
  53.         myEvent();  
  54.   
  55.         //显示窗体  
  56.         f.setVisible(true);  
  57.     }  
  58.   
  59.     private void myEvent()  
  60.     {  
  61.         //定义事件,点击exitButton,就退出  
  62.         exitButton.addActionListener(new ActionListener()  
  63.         {  
  64.             public void actionPerformed(ActionEvent e)  
  65.             {  
  66.                 System.exit(0);  
  67.             }  
  68.         });  
  69.         //点击zhuandaoButton按钮,就会将文本行中的数据添加到文本区域中  
  70.         zhuandaoButton.addActionListener(new ActionListener()  
  71.         {  
  72.             public void actionPerformed(ActionEvent e)  
  73.             {  
  74.                 //tf.getText("");  
  75.                 String text = tf.getText();  
  76.                 //System.out.println(text);  
  77.                 ta.append(text);  
  78.                 ta.append("");  
  79.   
  80.             }  
  81.         });  
  82.   
  83.         //关闭事件  
  84.         f.addWindowListener(new WindowAdapter()  
  85.         {  
  86.             public void windowClosing(WindowEvent e)  
  87.             {  
  88.                 System.exit(0);  
  89.             }  
  90.               
  91.         });  
  92.     }  
  93.     public static void main(String[] args)   
  94.     {  
  95.         new MyWindowDemo();  
  96.       
  97.     }  
  98.   
  99.     /*public static void showFrame()  
  100.     {  
  101.         Frame f = new Frame("对话框");  
  102.         f.setBounds(300,200,500,300);  
  103.         f.setLayout(new FlowLayout());  
  104.         Dialog d = new Dialog(f,true);  
  105.         Button button = new Button("转到");  
  106.         f.add(d);  
  107.         f.add(button);  
  108.         f.setVisible(true);  
  109.     }  
  110.     */  
  111. }  

0 0
原创粉丝点击