?? userlogon.java~4~
字號:
package com.soft.QQ;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.DatagramPacket;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class UserLogon
extends JFrame {
DatagramSocket socket=null;
DatagramPacket mail_packge=null;
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel la1 = new JLabel();
JTextField tf1 = new JTextField();
JLabel la2 = new JLabel();
JTextField tf2 = new JTextField();
JButton button1 = new JButton();
JButton button2 = new JButton();
public UserLogon() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(400, 300));
setTitle("用戶登入");
la1.setText("用戶昵稱");
la2.setText("服務器IP");
tf2.setText("127.0.0.1");
button1.setText("登入");
button1.addActionListener(new UserLogon_button1_actionAdapter(this));
button2.setText("重置");
button2.addActionListener(new UserLogon_button2_actionAdapter(this));
contentPane.setBackground(Color.cyan);
contentPane.add(la1, new XYConstraints(27, 43, 120, 36));
contentPane.add(tf1, new XYConstraints(156, 42, 155, 36));
contentPane.add(la2, new XYConstraints(25, 109, 121, 38));
contentPane.add(tf2, new XYConstraints(155, 108, 155, 34));
contentPane.add(button1, new XYConstraints(83, 190, 97, 33));
contentPane.add(button2, new XYConstraints(216, 187, 86, 33));
}
/**
* 向服務端發送用戶信息數據包
* @param sender String
* @param IP String
* @param i int
*/
public void sendUserInfo(String sender, String IP, int i) {
try {
socket = new DatagramSocket(3000);
byte[] buf = new Helper().wrapUserInfo(sender, IP, i);
mail_packge = new DatagramPacket(buf, buf.length,
InetAddress.getByName(tf2.getText()),
5000);
socket.send(mail_packge);
}
catch (Exception ex) {
ex.printStackTrace();
}finally {
if (socket != null) {
socket.close();
}
}
}
public void button2_actionPerformed(ActionEvent e) {
tf1.setText(null);
tf2.setText(null);
}
public void button1_actionPerformed(ActionEvent e) {
sendUserInfo(tf1.getText(),InetAddress.getLocalHost().getHostAddress(),2);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception exception) {
exception.printStackTrace();
}
new ClientWin();
}
});
}
}
class UserLogon_button1_actionAdapter
implements ActionListener {
private UserLogon adaptee;
UserLogon_button1_actionAdapter(UserLogon adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}
class UserLogon_button2_actionAdapter
implements ActionListener {
private UserLogon adaptee;
UserLogon_button2_actionAdapter(UserLogon adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button2_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -