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

📄 filerecive.java

📁 类似qq的以c/s结构和p2p结构结合的聊天软件。
💻 JAVA
字号:
package com.client;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.net.Socket;
import java.net.ServerSocket;
import java.io.*;

public class FileRecive extends JFrame implements Runnable
{

	private JTextField  filePath;
	private static Socket socket;
	private static FileOutputStream fout;
	private static InputStream in;
	private static int port;
	public FileRecive(Socket socket) 
	{
		super();
		setIconImage(new ImageIcon(this.getClass().getResource("image/bird.jpg")).getImage());
		this.socket=socket;		
		/*try
		{
			ServerSocket fileServerSocket=new ServerSocket(port);
			this.socket=fileServerSocket.accept();
		}catch(Exception de){}*/
		
		setVisible(true);
		getContentPane().setLayout(null);
		setBounds(100, 100, 305, 188);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JLabel label = new JLabel();
		label.setText("文件另存为");
		label.setBounds(25, 21, 138, 23);
		getContentPane().add(label);

		filePath = new JTextField();
		filePath.setBounds(25, 50, 195, 20);
		getContentPane().add(filePath);

		final JButton button = new JButton();
		button.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				FileSelect file=new FileSelect("save");
				filePath.setText(file.getFile());
			}
		});
		button.setText("浏览");
		button.setBounds(226, 48, 61, 23);
		getContentPane().add(button);

		final JButton save = new JButton();
		save.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				try
				{
					fout=new FileOutputStream(filePath.getText());
					in=FileRecive.socket.getInputStream();
					byte[] b=new byte[10000];
					while(in.read(b)!=-1)
					{
						fout.write(b);
					}
					fout.flush();
					fout.close();
					dispose();
					MessageDialog dialog=new MessageDialog("文件接收完毕!");
	    	        dialog.setSize(431,363);
	    	        dialog.setVisible(true);
				}catch(Exception e){}
				
			}
		});
		save.setText("保存");
		save.setBounds(191, 98, 71, 23);
		getContentPane().add(save);

		final JButton desert = new JButton();
		desert.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				dispose();
			}
		});
		desert.setText("放弃");
		desert.setBounds(47, 98, 71, 23);
		getContentPane().add(desert);
		//
	}
	
	public void run()
	{
		/*try
		{
			ServerSocket fileServerSocket=new ServerSocket(port);
			this.socket=fileServerSocket.accept();
		}catch(Exception de){}*/
	}

}

⌨️ 快捷键说明

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