📄 pwdtext.java
字号:
package clientGui;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.event.*;
public class PWDText extends JFrame{
private JPanel mainPanel = null;
private JPanel userNamePanel = null;
private JPanel passwordPanel = null;
private JLabel userName = null;
private JLabel password = null;
private JTextField inputUserName = null;
private JPasswordField inputPWD = null;
private JButton login = null;
static boolean visible = false;
private String getUserName;
private String getPWD;
private ClientGui clientGui = null;
private JLabel getUserName() {
if (userName == null) {
userName = new JLabel("username:");
userName.setBounds(0, 0, 10, 10);
}
return userName;
}
private JTextField getInputUserName() {
if (inputUserName == null) {
inputUserName = new JTextField(15);
inputUserName.setEditable(true);
inputUserName.setText("");
}
return inputUserName;
}
private JLabel getPassword() {
if (password == null) {
password = new JLabel("password:");
password.setBounds(0,12,10,10);
}
return password;
}
private JPasswordField getInputPWD() {
if (inputPWD == null) {
inputPWD = new JPasswordField("",15);
inputPWD.setEditable(true);
inputPWD.setEchoChar('*');
}
return inputPWD;
}
private JButton getLoginButton() {
if (login == null) {
login = new JButton("login");
}
return login;
}
private JPanel getUserPanel() {
if (userNamePanel == null) {
userNamePanel = new JPanel();
BorderLayout g = new BorderLayout();
g.setHgap(1);
g.setVgap(2);
userNamePanel.setLayout(g);
userNamePanel.add(getUserName(),BorderLayout.WEST);
userNamePanel.add(getInputUserName(),BorderLayout.EAST);
}
return userNamePanel;
}
private JPanel getPasswordPanel() {
if (passwordPanel == null) {
passwordPanel = new JPanel();
BorderLayout g = new BorderLayout();
g.setHgap(1);
g.setVgap(2);
passwordPanel.setLayout(g);
passwordPanel.add(getPassword(),BorderLayout.WEST);
passwordPanel.add(getInputPWD(),BorderLayout.EAST);
}
return passwordPanel;
}
private JPanel getMainPanel() {
if (mainPanel == null) {
mainPanel = new JPanel();
BorderLayout g = new BorderLayout();
g.setHgap(1);
g.setVgap(2);
mainPanel.setLayout(g);
mainPanel.add(getUserPanel(), java.awt.BorderLayout.NORTH);
mainPanel.add(getPasswordPanel(), java.awt.BorderLayout.CENTER);
mainPanel.add(getLoginButton(), java.awt.BorderLayout.SOUTH);
}
return mainPanel;
}
private void initialize() {
visible = true;
this.setContentPane(getMainPanel());
this.setTitle("login");
this.setBounds(390, 310, 250, 113);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {
if(!inputUserName.getText().equals("") &&
!String.valueOf((inputPWD.getPassword())).equals("")){
getUserName = inputUserName.getText();
getPWD = String.valueOf(inputPWD.getPassword());
boolean ok = clientGui.do_login(getUserName,getPWD);
if (!ok) {
JOptionPane.showMessageDialog(null, "Login unsuccesful", "ERROR", JOptionPane.ERROR_MESSAGE);
}
else {
visible = false;
}
}
else if (inputUserName.getText().equals("")){
JOptionPane.showMessageDialog(null, "Username can't be Empty", "ERROR", JOptionPane.ERROR_MESSAGE);
}
else if (String.valueOf((inputPWD.getPassword())).equals("")){
JOptionPane.showMessageDialog(null, "Password can't be Empty", "ERROR", JOptionPane.ERROR_MESSAGE);
}
else {
}
if (!visible) {
setThisVisible(false);
}
}
});
}
public void setThisVisible(boolean v) {
this.setVisible(v);
}
public String returnUserName() {
return getUserName;
}
public String returnPWD() {
return getPWD;
}
public PWDText(ClientGui cg) {
super();
clientGui = cg;
initialize();
}
public void setupClosing() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
}
public void removeUpdate(DocumentEvent e) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -