?? login.java
字號:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Login implements ActionListener{
JFrame jf = new JFrame("login");
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JLabel l1 = new JLabel("please input your name:");
JLabel l2 = new JLabel("input server's IP address:");
JTextField t1 = new JTextField();
JTextField t2 = new JTextField("127.0.0.1");
JButton b=new JButton("Login");
public static void main(String[] args)
{
Login aa= new Login();
}
public Login(){//構造方法
p1.setLayout(new GridLayout(2,2));
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(t2);
p2.setLayout(new FlowLayout());
p2.add(b);
jf.getContentPane().add(p1,"North");//JFrame jf
jf.getContentPane().add(p2);//默認添加到Center
jf.pack();
jf.setLocation(300,200);
//jf.show();已過時
jf.setVisible(true);
t2.addActionListener(this);
b.setMnemonic(KeyEvent.VK_L);
b.setToolTipText("按此鍵登錄");
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(t1.getText().equals("") && t2.getText().equals(""))//當沒有輸入用戶名&服務器IP時
{
//System.out.println("Please input your loginname and servername");
JOptionPane.showMessageDialog(null,"請輸入用戶名和服務器ip","系統提示",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
else if(t2.equals(""))//當沒有輸入服務器IP
{
//System.out.println("Please input the Chat server you want to connect.");
JOptionPane.showMessageDialog(null,"請輸入服務器ip","系統提示",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
else//如果輸入合法,則與服務器建立連接,開始聊天
{
TestClient c=new TestClient(t1.getText(),t2.getText());
jf.setVisible(false);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -