DOC

02-AWT

By Laurie Hughes,2014-10-08 22:31
17 views 0
02-AWT

    目录

    1知识点 ............................................................................................................................................ 1 1.1上次课程的主要知识点 ........................................................................................................... 1 1.2 本次预计讲解的知识点 .......................................................................................................... 2 2具体内容 ........................................................................................................................................ 2 2.1 AWT .......................................................................................................................................... 2

     2.2 示例......................................................................................................................................... 3

     3 总结 ............................................................................................................................................. 12

    4 作业 ............................................................................................................................................. 12

    课程名称,02-AWT 1知识点

    1.1上次课程的主要知识点

    1

    2

    1.2 本次预计讲解的知识点

     1AWT

     2

2具体内容

    2.1 AWT

     |- 容器

     |- Frame 顶层容器

     |- Dialog 顶层容器

     |- Panel 非顶层容器

     |- 组件

     |- Label 标签 ?用来显示文本或图片,

     |- Button 按钮

     |- TextField 文本框

     …….

     |- 布局管理器

     |- 绝对位置布局

     |- 网格布局 GridLayout

     |- 边框布局 BorderLayout

     |- 事件

2.2 示例

     完成一个登录界面 , 连接mysql数据库!实现登录验证。

    FrmLogin

    package com.whos.javase.course_02.view;

import java.awt.Button;

    import java.awt.Frame;

    import java.awt.Label;

    import java.awt.Panel;

    import java.awt.TextField;

    import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener;

    import javax.swing.JOptionPane;

import com.whos.javase.course_02.dao.UserInfoDao;

    import com.whos.javase.course_02.entity.UserInfo;

    public class FrmLogin extends Frame{

     //将窗体上的组件作为窗体的属性

     private Panel panel ;

     private Label lblUsername ;

     private Label lblPassword;

     private TextField txtUsername;

     private TextField txtPassword;

     private Button btnLogin;

     private Button btnReg;

     //初始化窗体

     public FrmLogin(){

     //设置窗体位置及大小

     //super.setBounds(200, 100, 300, 200);

     //设置窗体大小

     super.setSize(300, 200);

     panel = new Panel();

     //设置布局方式

     panel.setLayout(null);//绝对位置布局

     super.add(panel) ;

     lblUsername = new Label();

     lblUsername.setBounds(50, 20, 50, 20);

     lblUsername.setText("用户名:");

     panel.add(lblUsername);

     txtUsername = new TextField();

     txtUsername.setBounds(100, 20, 100, 20);

     panel.add(txtUsername);

     lblPassword = new Label();

     lblPassword.setBounds(50, 50, 50, 20);

     lblPassword.setText("密码:");

     panel.add(lblPassword);

     txtPassword = new TextField();

     txtPassword.setBounds(100, 50, 100, 20);

     panel.add(txtPassword);

     btnLogin = new Button();

     btnLogin.setBounds(120, 80, 30, 20);

     btnLogin.setLabel("登录");

     panel.add(btnLogin);

     btnReg = new Button();

     btnReg.setBounds(160, 80, 30, 20);

     btnReg.setLabel("注册");

     panel.add(btnReg);

     //添加登录的点击事件

     btnLogin.addActionListener(new ActionListener(){

     public void actionPerformed(ActionEvent e) {

     //点击按钮时!会调用此方法

     btnLoginClick(e);

     }

     });

     //添加注册点击事件

     btnReg.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent e) {