📄 maglogindemo.java
字号:
/**
* @(#)MagLoginDemo.java
*
*
* @author
* @version 1.00 2006/7/9
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;//JPasswordField 是一个轻量级组件,允许编辑单行文本,其视图指示键入内容,但不显示原始字符
public class MagLoginDemo extends Frame {
Panel p,pInput,pBut;
Label lbName,lbPwd;
TextField tfName;
JPasswordField tfPwd;
Button sure,cancle;
ManagementTest mTest = null;
/**
* Creates a new instance of <code>MagLoginDemo</code>.
*/
public MagLoginDemo() {
super("登入界面");
this.init();
}
public void init(){
p = new Panel();
pInput = new Panel();
pBut = new Panel();
lbName = new Label("输入用户名");
lbPwd = new Label("输入密码");
tfName = new TextField(40);
tfPwd = new JPasswordField(40);
tfPwd.setEchoChar('*');
sure = new Button("确定");
cancle = new Button("重设");
p.setLayout(new BorderLayout(5,5));
pInput.setLayout(new GridLayout(4,1));
pBut.setLayout(new GridLayout(1,2,5,5));
pInput.add(lbName);
pInput.add(tfName);
pInput.add(lbPwd);
pInput.add(tfPwd);
pBut.add(sure);
pBut.add(cancle);
sure.addActionListener(new OnClickDemo());
cancle.addActionListener(new OnClickDemo());
p.add(pInput,BorderLayout.CENTER);
p.add(pBut,BorderLayout.SOUTH);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
}
});
p.setBackground(Color.cyan);
this.add(p);
this.pack();
this.setSize(250,200);
this.setLocation(500,250);
this.setResizable(false);
this.setVisible(true);
}
private class OnClickDemo implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("确定")){
if(tfName.getText().equals("admin") && tfPwd.getText().equals("123456")){
if(mTest == null){
mTest = new ManagementTest();
dispose();
}
else
mTest.setVisible(true);
}
else
JOptionPane.showMessageDialog(null, "请输入正确用户名和密码");
}
else if(e.getActionCommand().equals("重设")){
tfName.setText("");
tfPwd.setText("");
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new MagLoginDemo();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -