📄 login.java
字号:
package chat1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login extends JFrame implements ActionListener{
/**
*
*/
private static final long serialVersionUID = -1032166884261196679L;
private TextField text1;
private TextField text2;
private Label lb1;
private Label lb2;
private Button bt1;
private Button bt2;
public Login(){
this.setLayout(null);
this.setTitle("Welcome to login!");
this.setBounds(400, 200, 300, 220);
lb1 = new Label("请输入帐号:");
lb1.setBounds(20, 40, 70, 25);
this.add(lb1);
lb2 = new Label("请输入密码:");
lb2.setBounds(20, 80, 70,25);
this.add(lb2);
text1 = new TextField("中文或英文");
text1.setBackground(Color.orange);
text1.setBounds(120, 40,100, 25);
text1.addActionListener(new myActionLisener());
this.add(text1);
text2 = new TextField(4);
text2.setBackground(Color.orange);
text2.setBounds(120, 80, 100, 25);
text2.setEchoChar('*');
text2.addActionListener(new myActionLisener());
text2.addTextListener(new myTextListener());
this.add(text2);
bt1 = new Button("确定");
bt1.setBounds(40,120,70,25);
bt1.addActionListener(this);
this.add(bt1);
bt2 = new Button("取消");
bt2.setBounds(140,120,70,25);
bt2.addActionListener(null);
this.add(bt2);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBackground(Color.yellow);
this.setVisible(true);
}
class myActionLisener implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==text1){
if(text1.getText().trim().length()>0)
text1.transferFocus();
}
if(e.getSource()==text2){
JOptionPane.showMessageDialog(null,"密码正确,准备登录");
//text2.setText("");
}
if(e.getSource()==bt2){
System.exit(0);
}
}
}
class myTextListener implements TextListener{
public void Textvaluechanged(TextEvent e){
if(text2.getText().equals(""));
{ JOptionPane.showMessageDialog(null,"密码有误,重新输入");
System.exit(0);
}
}
public void textValueChanged(TextEvent arg0) {
// TODO 自动生成方法存根
}
}
/**
* @param args
*/
public static void main(String[] args) {
new Login();
}
public void actionPerformed(ActionEvent evt) {
if(evt.getSource()== bt1){
new Chat_client();
}
// TODO 自动生成方法存根
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -