📄 logongui.java
字号:
package chatDog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class LogonGUI implements Const {
private String message=null;
private String caption=null;
private String userName=null;
private String userPassword=null;
JLabel userNamelbl=new JLabel("请输入你的用户名:");
JLabel userPasswordlbl=new JLabel(" 请输入你的密码:");
JTextField userNamejtf=new JTextField(20);
JPasswordField userPasswordjtf=new JPasswordField(20);
JButton btnRegist=new JButton(BTN_REGISTCAP);
JButton btnCancel=new JButton(BTN_CANCELCAP);
JButton btnLogon=new JButton(BTN_LOGONCAP);
JFrame lgf=new JFrame(caption);
private class btnAction implements ActionListener{
public void actionPerformed(ActionEvent e){
if((e.getActionCommand()).equals(BTN_LOGONCAP)){
userName=new String(userNamejtf.getText());
userPassword=new String(userPasswordjtf.getText());
message=new String(BTN_LOGONCAP);
}
else if((e.getActionCommand()).equals(BTN_CANCELCAP)){
message=new String(BTN_CANCELCAP);
}
else{
userName=new String(userNamejtf.getText());
userPassword=new String(userPasswordjtf.getText());
message=new String(BTN_REGISTCAP);
}
}
}
LogonGUI(String cap){
caption=cap;
}
public void start(){
lgf.setTitle(caption);
lgf.setSize(400,200);
lgf.setLocation(330,200);
lgf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
message=BTN_CANCELCAP;
}
});
btnAction ba=new btnAction();
btnRegist.addActionListener(ba);
btnCancel.addActionListener(ba);
btnLogon.addActionListener(ba);
lgf.getContentPane().setLayout(new FlowLayout());
lgf.getContentPane().add(userNamelbl);
lgf.getContentPane().add(userNamejtf);
lgf.getContentPane().add(userPasswordlbl);
lgf.getContentPane().add(userPasswordjtf);
lgf.getContentPane().add(btnRegist);
lgf.getContentPane().add(btnCancel);
lgf.getContentPane().add(btnLogon);
lgf.setVisible(true);
}
public void hide(){
lgf.setVisible(false);
}
public void reset(){
message=null;
}
public String getMessage(){
if(message==null) return null;
return new String(message);
}
public String getName(){
if(userName==null) return null;
return new String(userName);
}
public String getPassword(){
if(userPassword==null) return null;
return new String(userPassword);
}
public JFrame getFrame(){
return lgf;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -