java登錄文本框案例練習
package tuxing.com;
import javax.swing.*;
import java.awt.*;
/**
* 一個登陸文本框
*
*/
public class test_05 extends JFrame {
//定義組件
JPanel jp1,jp2,jp3;
JLabel jlb1,jlb2;
JButton jb1,jb2;
JTextField jtf1;
JPasswordField jpf1;
public static void main(String[] args) {
test_05 ts=new test_05();
}
//構造函數
public test_05(){
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jlb1 = new JLabel("用戶名");
jlb2 = new JLabel("密 碼");
jb1 = new JButton("登陸");
jb2 =new JButton("取消");
jtf1 = new JTextField(10);
jpf1 = new JPasswordField(10);
//設置佈局管理器
this.setLayout(new GridLayout(3,1));
//加入各個組件
jp1.add(jlb1);
jp1.add(jtf1);
jp2.add(jlb2);
jp2.add(jpf1);
jp3.add(jb1);
jp3.add(jb2);
//加入到JFrame
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setSize(300,150);
this.setLocation(200,200);
this.setResizable(false);//false表示不能隨意改變顯示框的大小
this.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
/**
* 一個登陸文本框
*
*/
public class test_05 extends JFrame {
//定義組件
JPanel jp1,jp2,jp3;
JLabel jlb1,jlb2;
JButton jb1,jb2;
JTextField jtf1;
JPasswordField jpf1;
public static void main(String[] args) {
test_05 ts=new test_05();
}
//構造函數
public test_05(){
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jlb1 = new JLabel("用戶名");
jlb2 = new JLabel("密 碼");
jb1 = new JButton("登陸");
jb2 =new JButton("取消");
jtf1 = new JTextField(10);
jpf1 = new JPasswordField(10);
//設置佈局管理器
this.setLayout(new GridLayout(3,1));
//加入各個組件
jp1.add(jlb1);
jp1.add(jtf1);
jp2.add(jlb2);
jp2.add(jpf1);
jp3.add(jb1);
jp3.add(jb2);
//加入到JFrame
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setSize(300,150);
this.setLocation(200,200);
this.setResizable(false);//false表示不能隨意改變顯示框的大小
this.setVisible(true);
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.