59 lines
2.0 KiB
Java
59 lines
2.0 KiB
Java
|
|
package 大作业;
|
||
|
|
|
||
|
|
import java.awt.GridLayout;
|
||
|
|
|
||
|
|
import javax.swing.JButton;
|
||
|
|
import javax.swing.JFrame;
|
||
|
|
import javax.swing.JTextField;
|
||
|
|
import javax.swing.JLabel;
|
||
|
|
import java.awt.event.*;
|
||
|
|
|
||
|
|
|
||
|
|
public class Log_In_frame extends JFrame{
|
||
|
|
private JLabel username_JLabel=new JLabel("用户名");
|
||
|
|
private JLabel InetAddress_JLable=new JLabel("连接IP");
|
||
|
|
private JTextField username_JTextField=new JTextField();
|
||
|
|
private JTextField InetAddress_JTextField=new JTextField();
|
||
|
|
private JButton button1=new JButton("连接");
|
||
|
|
private JButton button2=new JButton("建立主机");
|
||
|
|
public String username;
|
||
|
|
public String IP;
|
||
|
|
public int option;
|
||
|
|
|
||
|
|
public Log_In_frame(){
|
||
|
|
option=0;
|
||
|
|
setSize(300,300);
|
||
|
|
setLocationRelativeTo(null);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
|
|
setLayout(new GridLayout(3,3));
|
||
|
|
add(username_JLabel);add(username_JTextField);
|
||
|
|
add(InetAddress_JLable);add(InetAddress_JTextField);
|
||
|
|
add(button1);add(button2);
|
||
|
|
|
||
|
|
button1.addActionListener(new ActionListener() {
|
||
|
|
public void actionPerformed(ActionEvent e){
|
||
|
|
username=username_JTextField.getText();
|
||
|
|
IP=InetAddress_JTextField.getText();
|
||
|
|
option=1;
|
||
|
|
ChatingRoom chatingRoom=new ChatingRoom(username,IP,option);
|
||
|
|
chatingRoom.setTitle(username);
|
||
|
|
new Thread(chatingRoom).start();
|
||
|
|
dispose();
|
||
|
|
|
||
|
|
}
|
||
|
|
});
|
||
|
|
button2.addActionListener(new ActionListener() {
|
||
|
|
public void actionPerformed(ActionEvent e){
|
||
|
|
username=username_JTextField.getText();
|
||
|
|
IP=InetAddress_JTextField.getText();
|
||
|
|
option=2;
|
||
|
|
ChatingRoom chatingRoom=new ChatingRoom("(主机)"+username,IP,option);
|
||
|
|
chatingRoom.setTitle("(主机)"+username);
|
||
|
|
new Thread(chatingRoom).start();
|
||
|
|
dispose();
|
||
|
|
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|