📄 loginwindow.java
字号:
package com.lovo.event;
import java.awt.Container;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.ServerSocket;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginWindow extends JFrame{
public void init()
{ //界面窗口
this.setSize(400, 300);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setTitle("登陆");
this.setLocationRelativeTo(null);
}
//成员变量
JTextField userText;
JPasswordField userPwdText;
JButton button1;
JButton button2;
int port = 0;
public LoginWindow()
{ //具体设置
init();
Container contentPane = this.getContentPane();
contentPane.setLayout(null);
JLabel jl1 = new JLabel();
jl1.setText("用户名:");
jl1.setBounds(new Rectangle(94, 98, 42, 15));
userText = new JTextField();
userText.setBounds(162, 98, 81, 21);
JLabel jl2 = new JLabel();
jl2.setText("密 码:");
jl2.setBounds(new Rectangle(94, 146, 42, 15));
userPwdText = new JPasswordField();
userPwdText.setBounds(new Rectangle(162, 146, 81, 25));
button1 = new JButton();
button1.setBounds(new Rectangle(108, 210, 63, 25));
button1.addActionListener(new ActionListener()
{//事件监听
public void actionPerformed(ActionEvent e)
{
try
{//转换
port = Integer.parseInt(userText.getText().trim());
if(null != userPwdText.getPassword() && userPwdText.getPassword().length!=0)
{
LoginWindow.this.dispose();
new ChatWindow(port);//设置
}
}
catch(NumberFormatException e1)
{
userText.setText("用户名输入有误");
}
}
});
button1.setText("登陆");
//事件监听
button2 = new JButton();
button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
//加入组件
button2.setBounds(new Rectangle(197, 210, 63, 25));
button2.setText("取消");
contentPane.add(jl1);
contentPane.add(userText);
contentPane.add(jl2);
contentPane.add(userPwdText);
contentPane.add(button1);
contentPane.add(button2);
this.setVisible(true);
}
public static void main(String[] args) {
new LoginWindow();//完成
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -