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

📄 frame1.java~21~

📁 这是一本关于高级软件工程的书籍
💻 JAVA~21~
字号:
package qqclient;

import java.awt.BorderLayout;
import java.net.*;
import java.io.*;
import javax.swing.JFrame;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JList;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.JLabel;

public class Frame1 extends JFrame implements WindowListener {
    XYLayout xYLayout1 = new XYLayout();
    JButton jButton1 = new JButton();
    JComboBox jComboBox1 = new JComboBox();
    TextField TextField1 = new TextField();
    List List1 = new List();
    Socket s=null;
    JButton jButton2 = new JButton();
    JTextField jTextField1 = new JTextField();
    JLabel jLabel1 = new JLabel();
    public Frame1() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(xYLayout1);
        this.addWindowListener(this);
        this.setSize(400,400);
        jButton1.setText("发送");
        jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
        jComboBox1.addActionListener(new Frame1_jComboBox1_actionAdapter(this));
        xYLayout1.setWidth(400);
        xYLayout1.setHeight(351);
        jButton2.setText("连接服务器");
        jLabel1.setText("服务器名称");
        this.getContentPane().add(jButton1, new XYConstraints(308, 261, 75, 23));
        this.getContentPane().add(jComboBox1, new XYConstraints(12, 260, 95, 24));
        this.getContentPane().add(TextField1,
        new XYConstraints(113, 259, 191, 27));
        this.getContentPane().add(List1, new XYConstraints(13, 23, 367, 227));
        this.getContentPane().add(jLabel1, new XYConstraints(33, 302, 96, 39));
        this.getContentPane().add(jButton2, new XYConstraints(260, 303, 102, 28));
        this.getContentPane().add(jTextField1,
                                  new XYConstraints(125, 305, 108, 28));
        this.setVisible(true);
        this.jComboBox1.addItem("所有人");
        s=new Socket("localhost",8080);
        new CInputStream(s.getInputStream()).start();
    }

    public static void main(String[] args) {
        Client.f=new Frame1();
    }

    /**
     * Invoked the first time a window is made visible.
     *
     * @param e WindowEvent
     * @todo Implement this java.awt.event.WindowListener method
     */
    public void windowOpened(WindowEvent e) {
    }

    /**
     * Invoked when the user attempts to close the window from the window's
     * system menu.
     *
     * @param e WindowEvent
     * @todo Implement this java.awt.event.WindowListener method
     */
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }

    /**
     * Invoked when a window has been closed as the result of calling dispose
     * on the window.
     *
     * @param e WindowEvent
     * @todo Implement this java.awt.event.WindowListener method
     */
    public void windowClosed(WindowEvent e) {
    }

    /**
     * Invoked when a window is changed from a normal to a minimized state.
     *
     * @param e WindowEvent
     * @todo Implement this java.awt.event.WindowListener method
     */
    public void windowIconified(WindowEvent e) {
    }

    /**
     * Invoked when a window is changed from a minimized to a normal state.
     *
     * @param e WindowEvent
     * @todo Implement this java.awt.event.WindowListener method
     */
    public void windowDeiconified(WindowEvent e) {
    }

    /**
     * Invoked when the Window is set to be the active Window.
     *
     * @param e WindowEvent
     * @todo Implement this java.awt.event.WindowListener method
     */
    public void windowActivated(WindowEvent e) {
    }

    /**
     * Invoked when a Window is no longer the active Window.
     *
     * @param e WindowEvent
     * @todo Implement this java.awt.event.WindowListener method
     */
    public void windowDeactivated(WindowEvent e) {
    }

    public void jButton1_actionPerformed(ActionEvent e) {
    if(e.getSource()==jButton1){
        try {
            PrintWriter pw = new PrintWriter(s.getOutputStream());
            String shuo=TextField1.getText();
            String ren=(String)jComboBox1.getSelectedItem();
            if(ren.equals("所有人")){
                pw.println("CAll:"+Client.f.getTitle()+"-"+ren+"="+shuo);
                this.List1.add("你对"+ren+"说"+shuo);
        }
            else{
                pw.println("COne"+Client.f.getTitle()+"-"+ren+"="+shuo);
            }
        } catch (IOException ex) {
          }
      }
    }

    public void jComboBox1_actionPerformed(ActionEvent e) {

    }
}


class Frame1_jComboBox1_actionAdapter implements ActionListener {
    private Frame1 adaptee;
    Frame1_jComboBox1_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jComboBox1_actionPerformed(e);
    }
}


class Frame1_jButton1_actionAdapter implements ActionListener {
    private Frame1 adaptee;
    Frame1_jButton1_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}
class CInputStream extends Thread{
    InputStream in;
    public CInputStream(InputStream in){
        this.in=in;
    }
    public void run(){
        BufferedReader buff=new BufferedReader(new InputStreamReader(in));
        while(true){
            String s = null;
            try {
                s = buff.readLine();
            } catch (IOException ex) {
            }
            String ss=s.substring(s.indexOf(":"));
            if(ss.equals("SOneLogin")){
                String sss=ss.substring(s.indexOf(":")+1);
                Client.f.setTitle(sss);
                Client.f.List1.add(sss+"已登陆");
            }
            if(ss.equals("SOne")){
                String xiaoxi=s.substring(s.indexOf(":")+1);
                String str=s.substring(s.indexOf("=")+1);
                String s1=xiaoxi.substring(xiaoxi.indexOf("="));
                Client.f.List1.add(s1+"对您说"+"===="+str);
            }
            if(ss.equals("SAll")){
                String xiaoxi=s.substring(s.indexOf(":")+1);
                String str=s.substring(s.indexOf("=")+1);
                String s1=xiaoxi.substring(xiaoxi.indexOf("="));
                Client.f.List1.add(s1+"对所有人说"+"===="+str);
            if(ss.equals("SAllLogin")){
                String zaixian=ss.substring(ss.indexOf(":")+1);
                String title=Client.f.getTitle();
                if(!zaixian.equals(title)){
                    Client.f.jComboBox1.addItem(zaixian);
                    Client.f.List1.add(zaixian+"已登陆");
                }
            }
            }
        }
    }

}
class Client{
    public static Frame1 f;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -