📄 login.java
字号:
/*
此类是创建邮件登录界面
*/
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
public class Login extends JDialog implements ActionListener
{
private static final int WINDOW_WIDTH=220;
private static final int WINDOW_HEIGHT=100;
private static final int FIELD_WIDTH=15;
private static final Point LOCATION=new Point(220,250);
private JLabel user_ID_Label=new JLabel("用户名");
private JTextField user_ID= new JTextField(FIELD_WIDTH);
private JLabel user_Password_Label=new JLabel("密码");
private JPasswordField user_Password= new JPasswordField(FIELD_WIDTH);
private JButton yes=new JButton("确定");
private JButton quit=new JButton("退出");
private Panel label=new Panel();
private Panel text=new Panel();
private Panel button=new Panel();
private Panel up=new Panel();
private Panel whole=new Panel();
private String userID,userPassword;
//初始化登录窗口
public Login(JFrame jf)
{
super(jf,"登录:",true);
setSize(WINDOW_WIDTH,WINDOW_HEIGHT);
label.setLayout(new GridLayout(2,1));
label.add(user_ID_Label);
label.add(user_Password_Label);
text.setLayout(new GridLayout(2,1));
text.add(user_ID);
text.add(user_Password);
button.setLayout(new GridLayout(1,2));
button.add(yes);
button.add(quit);
yes.addActionListener(this);
quit.addActionListener(this);
up.setLayout(new BorderLayout());
up.add(label,BorderLayout.WEST);
up.add(text,BorderLayout.EAST);
whole.setLayout(new BorderLayout());
whole.add(up,BorderLayout.NORTH);
whole.add(button,BorderLayout.CENTER);
add(whole);
setLocation(LOCATION);
setResizable(false);
show();
}
//返回用户名
public String getUserName()
{
return userID;
}
//返回用户密码
public String getUserPassword()
{
return userPassword;
}
//侦听事件接口
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="确定")
{
userID = user_ID.getText().trim();
userPassword = user_Password.getText().trim();
this.dispose();
}
else{
System.exit(1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -