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();
}
}