當前位置:編程學習大全網 - 編程軟體 - JAVA根據GUI相關知識,編程實現壹個簡單的用戶登錄界面。不考慮事件的處理,只實現界面。

JAVA根據GUI相關知識,編程實現壹個簡單的用戶登錄界面。不考慮事件的處理,只實現界面。

import?java.awt.FlowLayout;

import?java.awt.GridLayout;

import?javax.swing.JButton;

import?javax.swing.JComponent;

import?javax.swing.JFrame;

import?javax.swing.JLabel;

import?javax.swing.JPanel;

import?javax.swing.JPasswordField;

import?javax.swing.JTextField;

public?class?LoginFrame?extends?JFrame

{

public?LoginFrame()

{

setTitle("登錄");

setSize(300,?140);

setResizable(false);

setAlwaysOnTop(true);

setLayout(new?GridLayout(3,?1));

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

addComps();

setVisible(true);

}

private?void?addComps()

{

String[]?ts?=?{

"用戶名:",?"密碼:"

};

for(int?i?=?0;?i?<?ts.length;?i++)

{

JPanel?p1?=?new?JPanel(new?FlowLayout(FlowLayout.RIGHT));

JLabel?b1?=?new?JLabel(ts[i]);

p1.add(b1);

JComponent?f1?=?null;

if(i?==?0)

{

f1?=?new?JTextField(20);

}

else

{

f1?=?new?JPasswordField(20);

((JPasswordField)?f1).setEchoChar('*');

}

p1.add(f1);

add(p1);

}

JPanel?p?=?new?JPanel(new?FlowLayout(FlowLayout.CENTER));

JButton?b1?=?new?JButton("登錄");

JButton?b2?=?new?JButton("重置");

p.add(b1);

p.add(b2);

add(p);

}

public?static?void?main(String[]?args)

{

new?LoginFrame();

}

}

  • 上一篇:夢見和喜歡的人壹起走迷宮
  • 下一篇:什麽是現貨黃金中的ea
  • copyright 2024編程學習大全網