JAVA GUI 開發---簡單登陸界面

看起復雜,其實不復雜,嘿嘿!
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;java

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;測試

public class LoginJFrameTest {
 private JFrame jframe;
 private JLabel jlabel,jlabel1;
 private GridBagLayout gridbag;
 private GridBagConstraints constraints;
 private JTextField jtfield1;
 private JPasswordField jpfield1;
 private JButton jbutton1,jbutton2,jbutton3;
  
 public LoginJFrameTest(){
  jframe = new JFrame();
  jlabel = new JLabel();
  jlabel1 = new JLabel();
  jtfield1 = new JTextField();
  jpfield1 = new JPasswordField();
  gridbag = new GridBagLayout();
  jbutton1 = new JButton();
  jbutton2 = new JButton();
  jbutton3 = new JButton();
  
  init();
 }
 
 private void init(){
  jframe.setTitle("全屏幕測試");
  jlabel.setText("用戶名:");
  jlabel1.setText("密    碼:");
  jbutton1.setText("登    錄");
  jbutton2.setText("退    出");
  jbutton3.setText("更改密碼");
  jframe.setUndecorated(true);
  jframe.getGraphicsConfiguration().getDevice().setFullScreenWindow(jframe);
  jframe.setLayout(gridbag);
    
     //用戶名文本框顯示
     constraints = getGridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER,
        GridBagConstraints.NONE,new Insets(10,0,10,0),0,0);
    
     gridbag.setConstraints(jlabel, constraints);
  jframe.add(jlabel);
  
  //用戶名輸入框顯示
     constraints = getGridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER,
        GridBagConstraints.NONE,new Insets(10,0,10,0),100,0);
   
     gridbag.setConstraints(jtfield1, constraints);
     jframe.add(jtfield1);
     
     //密碼文本框顯示
     constraints = getGridBagConstraints(0,1,1,1,0,0,GridBagConstraints.CENTER,
       GridBagConstraints.NONE,new Insets(10,0,10,0),0,0);
     gridbag.setConstraints(jlabel1, constraints);
     jframe.add(jlabel1);
 
     //密碼輸入框顯示
  constraints = getGridBagConstraints(1,1,1,1,0,0,GridBagConstraints.CENTER,
       GridBagConstraints.NONE,new Insets(10,0,10,0),100,0);ip

  gridbag.setConstraints(jpfield1, constraints);
  jframe.add(jpfield1);
  
  //更改密碼按鈕顯示
  constraints = getGridBagConstraints(0,2,1,1,0,0,GridBagConstraints.CENTER,
       GridBagConstraints.NONE,new Insets(10,0,10,0),0,0);get

  gridbag.setConstraints(jbutton3, constraints);
  jframe.add(jbutton3);
  
  //登陸按鈕顯示
  constraints = getGridBagConstraints(1,2,1,1,0,0,GridBagConstraints.CENTER,
       GridBagConstraints.NONE,new Insets(10,0,10,0),0,0);it

  gridbag.setConstraints(jbutton1, constraints);
  jframe.add(jbutton1);io

  //退出按鈕顯示
  constraints = getGridBagConstraints(2,2,1,1,0,0,GridBagConstraints.CENTER,
       GridBagConstraints.NONE,new Insets(10,0,10,0),0,0);class

  gridbag.setConstraints(jbutton2, constraints);
  jframe.add(jbutton2);
  
 }
 
 private static GridBagConstraints getGridBagConstraints(int gridx,int gridy,int gridwidth,
   int gridheight,double weightx,double weighty,int anchor,int fill,Insets insets,
   int ipadx,int ipady){import

   return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty,
     anchor, fill, insets, ipadx, ipady);
 }
 
 public void showMe(){
  jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  jframe.setVisible(true);
 }
 
 public static void main(String[] args) {
  new LoginJFrameTest().showMe();
 }
}登錄

參數說明:grid

       gridx=0;   //放在第0列       gridy=0;   //放在第0行       gridwidth=1;   //組件的長度       gridheight=1;   //組件的高度       weightx=10;   //組件根據窗口的大小而變化,係數爲10,1       weighty=1;          anchor=GridBagConstraints.CENTER;   //組件大於放置空間位置時,將組件放置在中心       fill=GridBagConstraints.HORIZONTAL;   //顯示區域變化時,設置組件是否變化。       inset=new Insets(0,0,0,0);   //設置組件間上下左右間距       ipadx=0;   //設置組件內的間距       ipady=0;  

相關文章
相關標籤/搜索