📄 chat.java
字号:
/*
* Chat.java
*
* Created on 2007年10月15日, 下午1:34
*/
package chat;
import common.FileInfo;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.lang.Object;
/**
*
* @author olry
*/
public class Chat extends javax.swing.JFrame
{
private DatagramSocket socket;
private Chat ref;
public Chat()
{
initComponents();
UDPWorker uw=new UDPWorker();
Thread udpThread=new Thread(uw);
udpThread.start();
ref=this;
TCPWorker tw=new TCPWorker();
Thread tcpThread=new Thread(tw);
tcpThread.start();
}
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents()
{
jMenuBar2 = new javax.swing.JMenuBar();
jMenu2 = new javax.swing.JMenu();
jMenuBar3 = new javax.swing.JMenuBar();
jMenu3 = new javax.swing.JMenu();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
btnSend = new javax.swing.JButton();
txtIP = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtDetails = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
txtMessage = new javax.swing.JTextArea();
jLabel2 = new javax.swing.JLabel();
fileSend = new javax.swing.JButton();
txtFilePath = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
btnOpenFile = new javax.swing.JButton();
txtPort = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
menu = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu2.setText("Menu");
jMenuBar2.add(jMenu2);
jMenu3.setText("Menu");
jMenuBar3.add(jMenu3);
jLabel5.setText("jLabel5");
jLabel6.setText("jLabel6");
jLabel7.setText("jLabel7");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u8d85\u7ea7\u804a\u5929\u5668 Beta 1.1016\u7248-(olry)");
btnSend.setText("\u53d1\u9001\u6d88\u606f");
btnSend.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
execSend(evt);
}
});
txtIP.setText("192.168.7.1");
txtIP.addKeyListener(new java.awt.event.KeyAdapter()
{
public void keyPressed(java.awt.event.KeyEvent evt)
{
txtIPKeyPressed(evt);
}
});
jLabel1.setText("I P:");
txtDetails.setColumns(20);
txtDetails.setRows(5);
txtDetails.setDisabledTextColor(new java.awt.Color(255, 51, 51));
txtDetails.setEnabled(false);
jScrollPane1.setViewportView(txtDetails);
txtMessage.setColumns(20);
txtMessage.setRows(5);
txtMessage.addKeyListener(new java.awt.event.KeyAdapter()
{
public void keyPressed(java.awt.event.KeyEvent evt)
{
txtMessageKeyPressed(evt);
}
});
jScrollPane2.setViewportView(txtMessage);
jLabel2.setText(" \u6309ALT\u952e\u5feb\u901f\u53d1\u9001");
fileSend.setText("\u53d1\u9001\u6587\u4ef6");
fileSend.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
sendfile(evt);
}
});
txtFilePath.setText("D:\\java\\");
jLabel3.setText(" \u9009\u62e9\u8def\u5f84\uff1a");
btnOpenFile.setText("\u6253\u5f00\u6587\u4ef6");
btnOpenFile.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
execOpenFile(evt);
}
});
txtPort.setText("8888");
jLabel4.setText(" \u9009\u62e9\u7aef\u53e3\uff1a");
menu.setText("\u83dc\u5355");
jMenuItem1.setText("\u9000\u51fa");
jMenuItem1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jMenuItem1ActionPerformed(evt);
}
});
menu.add(jMenuItem1);
jMenuItem2.setText("\u5e2e\u52a9");
jMenuItem2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jMenuItem2ActionPerformed(evt);
}
});
menu.add(jMenuItem2);
jMenuBar1.add(menu);
setJMenuBar(jMenuBar1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(layout.createSequentialGroup()
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(txtFilePath)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel4)
.add(8, 8, 8)
.add(txtPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 381, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(txtIP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 106, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(btnSend, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
.add(btnOpenFile)))
.add(layout.createSequentialGroup()
.add(22, 22, 22)
.add(jLabel2))
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(fileSend, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)))
.addContainerGap())
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 217, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(8, 8, 8)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(txtIP, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(18, 18, 18)
.add(jLabel2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnSend)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 15, Short.MAX_VALUE)
.add(fileSend))
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)))
.add(8, 8, 8)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel3)
.add(txtFilePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnOpenFile)
.add(txtPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel4))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem2ActionPerformed
{//GEN-HEADEREND:event_jMenuItem2ActionPerformed
HelpFrame f=new HelpFrame();
f.setBounds(500,200,300,300);
f.setVisible(true);
}//GEN-LAST:event_jMenuItem2ActionPerformed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -