資源簡(jiǎn)介
package asc;
import java.awt.*;
import javax.swing.*;
public class cs extends JFrame{
//定義組件
JPanel jp1,jp2,jp3;//面板
JLabel jlb1,jlb2;//標(biāo)簽
JButton jb1,jb2;//按鈕
JTextField jtf;//文本
JPasswordField jpf;//密碼
public static void main(String[] args) {
cs win=new cs();
}
//構(gòu)造函數(shù)
public cs(){
//創(chuàng)建面板
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
//創(chuàng)建標(biāo)簽
jlb1=new JLabel("用戶名");
jlb2=new JLabel("密 碼");
//創(chuàng)建按鈕
jb1=new JButton("登錄");
jb2=new JButton("重置");
//創(chuàng)建文本框
jtf=new JTextField(10);
//創(chuàng)建密碼框
jpf=new JPasswordField(10);
//設(shè)置布局管理
this.setLayout(new GridLayout(3, 1));//網(wǎng)格式布局
//加入各個(gè)組件
jp1.add(jlb1);
jp1.add(jtf);
jp2.add(jlb2);
jp2.add(jpf);
jp3.add(jb1);
jp3.add(jb2);
//加入到JFrame
this.add(jp1);
this.add(jp2);
this.add(jp3);
//設(shè)置窗體
this.setTitle("用戶登錄");//窗體標(biāo)簽
this.setSize(300, 150);//窗體大小
this.setLocationRelativeTo(null);//在屏幕中間顯示(居中顯示)
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//退出關(guān)閉JFrame
this.setVisible(true);//顯示窗體
//鎖定窗體
this.setResizable(false);
}
}
代碼片段和文件信息
- 上一篇:HttpTools2.4
- 下一篇:Java記事本
評(píng)論
共有 條評(píng)論