import javax.swing.*;
/**
* Created by Administrator on 2015/4/13 0013.
* <p>
* 组件的绝对定位 : 使用的是 Compontent 类中的setBounds 方法
* <p>
* <p>
* setBounds x y 表示组件的位置 width height 组件的宽高
*/
public class chap15_10 {
public static void main(String[] args) {
JFrame frame = new JFrame("登陆窗口");
frame.setLayout(null);
JLabel lbLogin = new JLabel("用户名");
JTextField textLogin = new JTextField();
JLabel lbPassword = new JLabel("密码");
JTextField textPassword = new JTextField();
JButton btnCon = new JButton("连接");
JButton btnExit = new JButton("退出");
JButton btnPro = new JButton("属性");
//容器的大小位置定义
frame.setSize(400, 200);
frame.setLocation(300, 200);
//用户名 和输入框 的定位
lbLogin.setBounds(45,5,50,20);
textLogin.setBounds(100, 5, 210, 20);
lbPassword.setBounds(45, 35, 50, 20);
textPassword.setBounds(100, 35, 210, 20);
btnCon.setBounds(45, 100, 80, 20);
btnExit.setBounds(130, 100, 80, 20);
btnPro.setBounds(220, 100, 80, 20);
frame.add(lbLogin);
frame.add(textLogin);
frame.add(lbPassword);
frame.add(textPassword);
frame.add(btnCon);
frame.add(btnExit);
frame.add(btnPro);
frame.setVisible(true);
}
}
实现的效果图为: