?? 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 + -