📄 loginstart.java
字号:
package net.yangzhe.chatSocket;
import java.awt.BorderLayout;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
public class LoginStart extends JFrame {
private JPanel jContentPane = null;
String ip;
private JButton jButton = null;
private JTextField jTextField = null;
private JLabel jLabel = null;
private JLabel jLabel2 = null;
private LoginPanel loginPanel1 = null;
/**
* This is the default constructor
* @throws IOException
* @throws UnknownHostException
*/
public LoginStart() throws UnknownHostException, IOException {
super();
initialize();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
/**
* This method initializes this
*
* @return void
* @throws IOException
* @throws UnknownHostException
*/
private void initialize() throws UnknownHostException, IOException {
this.setSize(463, 329);
this.setLocation(new java.awt.Point(300,300));
this.setResizable(false);
this.setContentPane(getJContentPane());
this.setTitle("登陆");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
* @throws IOException
* @throws UnknownHostException
*/
private JPanel getJContentPane() throws UnknownHostException, IOException {
if (jContentPane == null) {
jLabel = new JLabel();
jLabel.setBounds(new java.awt.Rectangle(78,55,186,45));
jLabel.setText("输入服务器ip地址:");
jLabel2 = new JLabel();
jLabel2.setBounds(new java.awt.Rectangle(83,224,270,47));
jLabel2.setText("");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJTextField(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getLoginPanel1(), null);
loginPanel1.hide();
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new java.awt.Rectangle(140,164,146,39));
jButton.setText("检测服务器状态");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
Client client = new Client(InetAddress.getByName(jTextField.getText()));
client.sendNews("%t%tTestServer");
String r= client.getNews();
if(r.equals("%t%tOK")){
ip=jTextField.getText();
loginPanel1.connectServer(ip);
jLabel.hide();
jLabel2.hide();
jTextField.hide();
jButton.hide();
//jContentPane.add(getLoginPanel1(), null);
loginPanel1.show();
client.sendNews("%end");
client.sendNews("%end");
if(client.getNews()!=null)
client.server.close();
}else{
jLabel2.setText("Server occurs error.");
}
} catch (Exception e1) {
// TODO Auto-generated catch block
jLabel2.setText("The server is no found.");
e1.printStackTrace();
}
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setText("127.0.0.1");
jTextField.setBounds(new java.awt.Rectangle(76,111,274,37));
}
return jTextField;
}
/**
* This method initializes loginPanel1
*
* @return net.yangzhe.chatSocket.LoginPanel
* @throws IOException
* @throws UnknownHostException
*/
private LoginPanel getLoginPanel1() throws UnknownHostException, IOException {
if (loginPanel1 == null) {
loginPanel1 = new LoginPanel(ip);
loginPanel1.setBounds(new java.awt.Rectangle(59,22,338,263));
}
return loginPanel1;
}
public static void main(String[] args) throws UnknownHostException, IOException{
LoginStart ls =new LoginStart();
ls.show();
}
} // @jve:decl-index=0:visual-constraint="10,2"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -