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

📄 mainframe.java~7~

📁 一个java写的qq代码……大家用来学习 非常好用
💻 JAVA~7~
字号:
package lxl聊天系统客户端;

import java.awt.BorderLayout;
import java.awt.Dimension;


import javax.swing.JPanel;
import java.awt.Color;
import java.awt.SystemColor;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;
import javax.swing.UIManager;
import javax.swing.*;
import javax.swing.border.MatteBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.*;
import java.util.*;


public class MainFrame extends JFrame {
    JPanel contentPane;
     JPanel jPanel1 = new JPanel();
     Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
             Color.white, new Color(165, 163, 151));
     JLabel jLabel1 = new JLabel();
     Icon icon=new ImageIcon("0.jpg");
     JLabel jLabel2 = new JLabel();
     String [] a={"",""};
     JComboBox jComboBox1 = new JComboBox(a);
     JLabel jLabel3 = new JLabel();
     JPasswordField jPasswordField1 = new JPasswordField();
     JLabel jLabel4 = new JLabel();
     JLabel jLabel5 = new JLabel();
     JButton jButton1 = new JButton();
     JButton jButton2 = new JButton();
     JButton jButton3 = new JButton();
     Border border2 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
             new Color(0, 120, 255), new Color(0, 58, 158));
     Border border3 = new MatteBorder(icon);
     Socket socket=null;
     BufferedReader cin=null;
     PrintStream cout=null;
     String name;
     javax.swing.JLabel jLabel6 = new JLabel();

   class ReadMessageThread extends Thread{
       public void run(){
           String line="";
           while(true){
            try {
                line = cin.readLine();
            } catch (IOException ex) {
                jLabel6.setText("输入输出异常\n");
            }
            StringTokenizer st=new StringTokenizer(line,":");
            String keyword=st.nextToken();
            if(keyword.equalsIgnoreCase("NO")){
                String ms=st.nextToken("\n");
                jLabel6.setText(ms);
            }
            else if(keyword.equalsIgnoreCase("YES")){
                Frame1 f=new Frame1(name );
                f.setSize(280,750);
                f.setLocation(1000,0);
                f.setTitle("LXL聊天系统");
                f.show();
            }
           }
       }
   }
    public MainFrame() {
        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(null);
        this.setForeground(Color.pink);
        setSize(new Dimension(400, 330));
        setTitle("LXL聊天");
        contentPane.setBackground(new Color(231, 233, 235));
        jPanel1.setBackground(Color.white);
        jPanel1.setBorder(border1);
        jPanel1.setBounds(new Rectangle(6, 78, 387, 130));
        jPanel1.setLayout(null);
        jLabel1.setIcon(icon);
        jLabel1.setText("jLabel1");
        jLabel1.setBounds(new Rectangle( -1, 0, 401, 72));
        jLabel2.setText("账号:");
        jLabel2.setBounds(new Rectangle(35, 16, 89, 29));
        jComboBox1.setEditable(true);
        jComboBox1.setBounds(new Rectangle(134, 16, 168, 31));
        jLabel3.setText("密码:");
        jLabel3.setBounds(new Rectangle(34, 72, 89, 34));
        jPasswordField1.setBounds(new Rectangle(135, 75, 167, 31));
        jLabel4.setForeground(SystemColor.textHighlight);
        jLabel4.setText("申请账号");
        jLabel4.setBounds(new Rectangle(309, 13, 73, 31));
        jLabel5.setForeground(SystemColor.activeCaption);
        jLabel5.setText("忘记密码");
        jLabel5.setBounds(new Rectangle(308, 72, 73, 32));
        jButton1.setBackground(UIManager.getColor("ToolBar.dockingForeground"));
        jButton1.setBounds(new Rectangle(286, 217, 99, 36));
        jButton1.setBorder(BorderFactory.createEtchedBorder());
        jButton1.setText("登陆");
        jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this));
        //jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(8, 215, 99, 38));
        jButton2.setText("查杀木马");
        jButton3.setBackground(Color.lightGray);
        jButton3.setBounds(new Rectangle(111, 216, 92, 35));
        jButton3.setBorder(border2);
        jButton3.setText("设置↓");
        jLabel6.setBounds(new Rectangle(73, 262, 255, 32));
        contentPane.add(jPanel1);
        jPanel1.add(jLabel2);
        jPanel1.add(jComboBox1);
        jPanel1.add(jLabel3);
        jPanel1.add(jLabel4);
        jPanel1.add(jLabel5);
        jPanel1.add(jPasswordField1);
        contentPane.add(jLabel1);
        contentPane.add(jButton1);
        contentPane.add(jButton2);
        contentPane.add(jButton3);
        contentPane.add(jLabel6);

    }

    public void jButton1_actionPerformed(ActionEvent e) {
      name= jComboBox1.getSelectedItem().toString();
     String pa=new String(jPasswordField1.getPassword());
       try {
           InetAddress ip = InetAddress.getByName("127.0.0.1");
           int port=6544;
           socket=new Socket(ip,port);
           jLabel6.setText("与服务器开始连接……");
       } catch (Exception ex) {
         jLabel6.setText("服务器端口打开出错\n");
       }
          if(socket!=null){
              jLabel6.setText("连接成功……\n");
           try {
               cin=new BufferedReader(new InputStreamReader(socket.getInputStream()));
               cout = new PrintStream(socket.getOutputStream());
               String str="PEOPLE:"+name+":"+pa;
               cout.println(str);
               ReadMessageThread rs=new ReadMessageThread();
               rs.start();
           } catch (IOException ex1) {
           }
          }

    }
}


class MainFrame_jButton1_actionAdapter implements ActionListener {
    private MainFrame adaptee;
    MainFrame_jButton1_actionAdapter(MainFrame adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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