📄 chat.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. *//* * chat.java * * Created on 2009-2-20, 6:08:09 */package chatGUI;import MServer.Mserver;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Toolkit;import java.io.IOException;import java.net.InetAddress;import java.net.ServerSocket;import java.net.Socket;import java.net.UnknownHostException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.ImageIcon;import javax.swing.JLabel;import trans.MainF;import voice.yuyinclient;import voice.yuyinserver;/** * * @author Administrator */public class chat extends javax.swing.JFrame { private String nowtime; private String ip,localip; private ServerSocket serSock = null; private Socket cli = null; private yuyinserver yuyins = null; private yuyinclient yuyinc = null; //private String yuyinip; /** Creates new form chat */ public chat(String ip) throws UnknownHostException { initComponents(); JLabel lb = new JLabel(new ImageIcon("img\\chat.jpg")); back.setLayout(new BorderLayout()); back.add(lb, BorderLayout.CENTER); this.setVisible(true); this.setLocation(400, 200); this.ip = ip; this.setTitle(ip); yuyinaccept.setVisible(false); yuyinrefuse.setVisible(false); //get本地IP byte [] ip1=InetAddress.getLocalHost().getAddress(); localip = (ip1[0]&0xff)+"."+(ip1[1]&0xff)+"."+(ip1[2]&0xff)+"."+(ip1[3]&0xff); } public String getip(){ return ip; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { back = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); print = new javax.swing.JTextArea(); jPanel3 = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); write = new javax.swing.JTextArea(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jPanel5 = new javax.swing.JPanel(); yuyinaccept = new javax.swing.JButton(); yuyinrefuse = new javax.swing.JButton(); send = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jPanel2.setBackground(new java.awt.Color(204, 204, 255)); print.setBackground(new java.awt.Color(255, 255, 255)); print.setColumns(20); print.setFont(new java.awt.Font("宋体", 0, 14)); print.setForeground(new java.awt.Color(0, 0, 204)); print.setRows(5); print.setDisabledTextColor(new java.awt.Color(0, 0, 204)); print.setEnabled(false); jScrollPane1.setViewportView(print); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) ); jPanel3.setBackground(new java.awt.Color(204, 204, 255)); write.setBackground(new java.awt.Color(255, 255, 255)); write.setColumns(20); write.setRows(5); write.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { writeKeyPressed(evt); } }); jScrollPane2.setViewportView(write); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE) ); jButton1.setText("发送文件"); jButton1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("申请语音聊天"); jButton2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jPanel5.setBackground(new java.awt.Color(204, 204, 255)); yuyinaccept.setText("接受"); yuyinaccept.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); yuyinaccept.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { yuyinacceptActionPerformed(evt); } }); yuyinrefuse.setText("取消"); yuyinrefuse.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); yuyinrefuse.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { yuyinrefuseActionPerformed(evt); } }); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() .addGap(24, 24, 24) .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(yuyinrefuse, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE) .addComponent(yuyinaccept, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)) .addGap(20, 20, 20)) ); jPanel5Layout.setVerticalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(yuyinaccept) .addGap(18, 18, 18) .addComponent(yuyinrefuse) .addContainerGap(29, Short.MAX_VALUE)) ); send.setText("发送"); send.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); send.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendActionPerformed(evt); } }); jButton4.setText("关闭"); jButton4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jPanel1.setBackground(new java.awt.Color(204, 204, 255)); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 125, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -