5-13各種組件組合的登錄窗口+5-14我要自學網

import java.awt.*;
import java.io.File;


import javax.imageio.ImageIO;
import javax.swing.*;
public class JJ5_1222 extends JFrame
{


JPanel qqhy,south,tb1,tb2,tb3;
JLabel north,haoma,mima,wangjimima,shenqingmb;
JTextField hmt;
JPasswordField mmt;
JCheckBox yinshen,jizhumm;
JButton dl,qx,xd,tpb,qchm;
JTabbedPane putongyh;


public static void main(String[] args)
{
// TODO Auto-generated method stub
JJ5_1222 dl=new JJ5_1222();
}
public JJ5_1222()


{
//創建中間面板的按鈕
haoma=new JLabel("號碼");
hmt=new JTextField();
mmt=new JPasswordField();
mima=new JLabel("密碼");
wangjimima=new JLabel("忘記密碼");
shenqingmb=new JLabel("申請密碼保護");
qchm=new JButton(new ImageIcon("image/tt.png"));
yinshen=new JCheckBox("隱身登錄");
jizhumm=new JCheckBox("記住密碼");

//創建面板
putongyh=new JTabbedPane();
//qqhy=new JPanel();
north=new JLabel(new ImageIcon("image/tt.png"));//用JLabel添加圖片
south=new JPanel();
tb1=new JPanel();//設置面板的背景色
tb1.add(haoma);tb1.add(hmt);tb1.add(qchm);tb1.add(mima);tb1.add(mmt);tb1.add(wangjimima);tb1.add(yinshen);tb1.add(jizhumm);add(shenqingmb);

tb2=new JPanel();
tb2.setBackground(Color.blue);
tb3=new JPanel();


 
//定義按鈕
dl=new JButton("登錄");
qx=new JButton("取消");
xd=new JButton("sn");
tpb=new JButton(new ImageIcon("image/tt.png"));//按鈕裏面放圖片



//向中間面板添加組件
putongyh.add(tb1,"HI");
putongyh.add(tb2,"HII");
putongyh.add(tb3,"HIII");

//向tb1中添加組件
tb1.setLayout(new GridLayout(3,3));

//向NORTH面板中添加組件--添加按鈕
south.add(dl);
south.add(qx);
south.add(xd);

//定義佈局,添加圖片
this.add(north,BorderLayout.NORTH);
this.add(south,BorderLayout.SOUTH);//定義邊界佈局
this.add(putongyh);

//this.setIconImage((new ImageIcon("image\tt.png").getImage()));



//常用的屬性
this.setVisible(true);
this.setTitle("用戶界面");
this.setSize(400, 200);//像素
this.setLocation(200, 100);
//this.setResizable(false);
}


}


總結:

看到那麼多窗口和組件jpanel一個一個的分類,一個一個的填充有助於理清,

新知識 JTabbedPane tab頁  顧名思義,他是由多個jpanel組成的,所以之前要先創建多個jpanel,然後添加到jtabbedpane中

可以將borderlayout佈局的北部定義爲一個jlabel,然後jlabel可以添加背景圖片north=new JLabel(new ImageIcon("image/tt.png"));//用JLabel添加圖片

tb2.setBackground(Color.blue);//設置jpanel的背景色





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章