/*
* JPanel 使用
*/
package com.swing;
import java.awt.GridLayout;
import javax.swing.*;
class jpanel extends JFrame{
JPanel jp1,jp2,jp3;
JLabel jl1,jl2;
JTextField jtf1;
JPasswordField jpf1;
JButton jb1,jb2,jb3,jb4,jb5;
public static void main(String[] args){
jpanel ob_jpanel=new jpanel();
}
public jpanel(){
this.setLayout(new GridLayout(3,1));
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
//设置标签
jl1=new JLabel("用户名");
jl2=new JLabel("密码");
//设置文本框和密码框
jtf1=new JTextField(10);
jpf1=new JPasswordField(10);
//设置按钮
jb1=new JButton("登陆");
jb2=new JButton("取消");
jp1.add(jl1);
jp1.add(jtf1);
jp2.add(jl2);
jp2.add(jpf1);
jp3.add(jb1);
jp3.add(jb2);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setTitle("jpanel的使用");
this.setSize(300,150);
this.setLocation(100,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}