📄 loginframe.java
字号:
import java.awt.*;
import java.awt.event.*;
public class LoginFrame extends Frame{
TextField username1,password1;//登录id,密码输入
TextField username2,password2;//注册id,密码输入
Label lab1,lab2,lab3,lab4;
Button login,register;
ClientFrame client_frame;
public LoginFrame(ClientFrame cf)//构造函数
{
client_frame = cf;
setLayout(null);
username1=new TextField();
username2=new TextField();
password1=new TextField();
password2=new TextField();
lab1=new Label("user name:");
lab2=new Label("password:");
lab3=new Label("user name:");
lab4=new Label("password:");
lab1.setForeground (Color.white);
lab2.setForeground (Color.white);
lab3.setForeground (Color.white);
lab4.setForeground (Color.white);
add(lab1);
add(lab2);
add(lab3);
add(lab4);
lab1.setSize(65,20);
lab2.setSize(65,20);
lab3.setSize(65,20);
lab4.setSize(65,20);
lab1.setLocation(10,50);
lab2.setLocation(10,80);
lab3.setLocation(10,120);
lab4.setLocation(10,150);
username1=new TextField();
username1.setSize (150,20);
add(username1);
username1.setLocation (95,50);
password1=new TextField();
password1.setEchoChar ('*');
password1.setSize (150,20);
add(password1);
password1.setLocation (95,80);
login=new Button("Login");
login.setSize(60,20);
login.setLocation (275,80);
//-------------添加监听器 向服务器发送注册信息-------------------------
login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt)
{
String user_name = username1.getText();
String passwd = password1.getText();
client_frame.setName(user_name);
if(!user_name.equals("")&&!passwd.equals(""))
client_frame.out.println(MsgType.LOGON+" "+user_name+" "+passwd);
System.out.println("********** I am logged as "+user_name+"***********");
client_frame.setTitle((String)user_name+" is playing here...");
}
});
add(login);
username2=new TextField();
username2.setSize (150,20);
add(username2);
username2.setLocation (95,120);
password2=new TextField();
password2.setEchoChar ('*');
password2.setSize (150,20);
add(password2);
password2.setLocation (95,150);
register=new Button("Register");
register.setSize(60,20);
register.setLocation (275,150);
//-------------添加监听器 向服务器发送注册信息-------------------------
register.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt)
{
System.out.println(client_frame);
String user_name = username2.getText();
String passwd = password2.getText();
client_frame.setName(user_name);
if(!user_name.equals("")&&!passwd.equals(""))
client_frame.out.println(MsgType.REGISTER+" "+user_name+" "+passwd);
client_frame.out.flush();
client_frame.setTitle((String)user_name+" is playing here...");
}
});
add(register);
int ScreenWidth,ScreenHeight;
this.setSize(400,200);
setTitle("登录注册界面");
setResizable(false);
setBackground(Color.DARK_GRAY);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
//------------清空TextArea---------------------------------
public void clear()
{
password1.setText("");
password2.setText("");
username1.setText("");
username2.setText("");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -