⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userlogon.java~5~

📁 局域网聊天系统
💻 JAVA~5~
字号:
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) {
    try {
       sendUserInfo(tf1.getText(),InetAddress.getLocalHost().getHostAddress(),2);
    }
    catch (Exception ex) {}
    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 + -