当前位置: 代码迷 >> J2SE >> 本人打算用JTextPane做一个能发送图片的聊天程序,请教怎样才能把已经发送到对方电脑里的图片,拿出来显示在聊天框里面呢?做成类似QQ的效果
  详细解决方案

本人打算用JTextPane做一个能发送图片的聊天程序,请教怎样才能把已经发送到对方电脑里的图片,拿出来显示在聊天框里面呢?做成类似QQ的效果

热度:9006   发布时间:2013-02-25 00:00:00.0
本人打算用JTextPane做一个能发送图片的聊天程序,请问怎样才能把已经发送到对方电脑里的图片,拿出来显示在聊天框里面呢?做成类似QQ的效果
请问怎样将已经发送到对方电脑里的图片,通过指定的路径拿出来显示在聊天框里面呢?做成类似QQ发送图片的效果,请教各位高手
代码如下:
import java.awt.EventQueue;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.GregorianCalendar;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;



import java.awt.*;
import javax.swing.JPanel;


public class QQ<FontAttrib> extends JFrame {

JFrame frame;
private JScrollPane scrollPane_1 ; // 滚动
private JTextPane textPane_1 ;  
private StyledDocument doc; // 非常重要插入文字样式就靠它了
private StyledDocument dic ; // 非常重要插入文字样式就靠它了
JTextPane textPane = new JTextPane();  
  Toolkit tk;
  Vector picVector = new Vector();
  private JTextField textField;
  int length=1024;
byte[] sendBytes=new byte[1024];
GregorianCalendar time=new GregorianCalendar();
ByteArrayOutputStream baos = new ByteArrayOutputStream();  
 int a1=0;
 

 
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {

try {
QQ window = new QQ();
window.frame.setVisible(true);

} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public QQ() {

initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 625, 550);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
scrollPane_1 = new JScrollPane(textPane_1);



textPane.setBounds(0, 0, 442, 291);
frame.getContentPane().add(textPane);
dic = textPane.getStyledDocument();

final JTextPane textPane_1 = new JTextPane();
textPane_1.setBounds(0, 301, 442, 146);
frame.getContentPane().add(textPane_1);
doc = textPane_1.getStyledDocument();
 
textField = new JTextField();
textField.setBounds(10, 485, 432, 21);
frame.getContentPane().add(textField);
textField.setColumns(10);
 
JButton button = new JButton("\u56FE\u7247");