import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Client implements ActionListener {
	DataOutputStream output;

	BufferedInputStream bis;

	BufferedOutputStream bos;

	byte[] receivedData;
	int in;

	String strLine;
	public Font f = new Font("Times new roman", Font.BOLD, 18);
	public Font f1 = new Font("Times new roman", Font.BOLD, 28);
	public Font f2 = new Font("Times new roman", Font.BOLD, 20);
	public Font f3 = new Font("Arial Rounded MT Bold", Font.BOLD, 20);
	public JLabel T1 = new JLabel("CLIENT ");
	public JLabel T2 = new JLabel();

	public JLabel l = new JLabel("Received File");
	public JLabel l1 = new JLabel("Total Filesize :");
	public JTextField l2 = new JTextField();
	
	public JButton btn = new JButton("Search");
	public JButton graph = new JButton("Download");
	public JButton exit = new JButton("Exit");

	public JTextArea tf = new JTextArea();
	public JScrollPane pane = new JScrollPane();

	

	public JTextArea tf1 = new JTextArea();
	public JScrollPane pane1 = new JScrollPane();

	StringBuffer buffer = new StringBuffer();

	public JFrame jf;
	public Container c;
	JPanel jp = new JPanel();
	JPanel jp1 = new JPanel();
	JPanel jp2 = new JPanel();
	JPanel jp3 = new JPanel();
	
	

	Client() {

		jf = new JFrame(" Client");
		c = jf.getContentPane();
		c.setLayout(null);
		jf.setSize(800, 670);

		c.setBackground(Color.BLACK);

		T1.setBounds(420, 10, 950, 50);
		T2.setBounds(210, 50, 950, 50);
		T1.setForeground(new Color(195,110,250));
		T2.setForeground(Color.RED);

		l.setBounds(450, 200, 250, 35);

		l1.setBounds(520, 140, 250, 35);
		l2.setBounds(700, 140, 150, 35);
		

		l.setForeground(Color.BLUE);
		// l1.setForeground(new Color(120,0,0));
		l1.setForeground(Color.BLACK);
		l2.setForeground(Color.BLACK);
		
		l.setFont(f2);
		l1.setFont(f3);
		l2.setFont(f3);
		

		

		
		

		btn.setBounds(250, 130, 200, 35);
		btn.setFont(f2);
		btn.setForeground(new Color(120, 0, 0));

		graph.setBounds(240, 140, 200, 35);
		graph.setFont(f2);
		graph.setForeground(new Color(120, 0, 0));

		exit.setBounds(420, 625, 200, 35);
		exit.setFont(f2);
		exit.setForeground(new Color(120, 0, 0));

		tf.setForeground(Color.BLUE);
		tf1.setForeground(new Color(69, 39, 4));

		tf.setFont(f);
		tf1.setFont(f);

		jp.setBounds(70, 75, 900, 600);
		jp.setBackground(new Color(150, 150, 150));
		jp1.setBounds(65, 70, 910, 610);

		jp2.setBounds(200, 240, 650, 350);
		jp2.setBackground(new Color(100, 100, 100));
		jp3.setBounds(199, 239, 652, 352);
		jp3.setBackground(Color.BLACK);

		

		pane.setBackground(new Color(151, 242, 241));
		tf.setColumns(20);
		tf.setRows(10);
		tf.setName("tf");
		pane.setName("pane");
		pane.setViewportView(tf);
		pane.setBounds(230, 260, 580, 310);

		pane1.setBounds(570, 185, 350, 350);

		tf1.setColumns(20);
		tf1.setRows(10);
		tf1.setName("tf");
		pane1.setName("pane");
		pane1.setViewportView(tf1);

		T1.setFont(f1);
		T2.setFont(f1);

		exit.addActionListener(this);
		exit.setMnemonic(KeyEvent.VK_E);
		jf.show();
		c.add(pane, BorderLayout.CENTER);
		
		c.add(T1);

		 c.add(l1);
		
		c.add(exit);
		c.add(l);

		 c.add(l2);
		
		c.add(graph);
		c.add(jp2);
		c.add(jp3);
		
		c.add(jp);
		c.add(jp1);

		jf.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent win) {
				System.exit(0);
			}
		});

		int[] ports = new int[] { 8889, 9999 };

		for (int i = 0; i < 2; i++) {
			Thread t = new Thread(new PortListener(ports[i]));
			t.setName("Listener-" + ports[i]);
			t.start();

		}
	}

	public static void main(String args[]) {
		Client s = new Client();

	}

	class PortListener implements Runnable {

		BufferedOutputStream bos = null;

		ServerSocket server;
		Socket connection;
		BufferedReader br = null;
		int port;

		public PortListener(int port) {
			this.port = port;
		}

		public void run() {
			if (this.port == 8889) {
				try {

					server = new ServerSocket(port);

					while (true) {
						connection = server.accept();

						br = new BufferedReader(new InputStreamReader(
								new BufferedInputStream(connection
										.getInputStream())));

						String strLine;

						System.out.println("hi");
						while ((strLine = br.readLine()) != null) {

							System.out.println(strLine);
							buffer.append(strLine + "\n");

						}
						br.close();
						connection.close();
						// tf.setText(buffer.toString());

						/******************************************************************/
						/*******************************************************************/
						byte[] byteArray;
						Socket client = null;

					}
				} catch (IOException e) {

				} finally {

				}

			}

		}

	}

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == graph) {
		String tflen=buffer.toString();
		int a =tflen.length();
		String str=Integer.toString(a);
		l2.setText(str.toString());
			tf.setText(buffer.toString());

		}
		if (e.getSource() == exit) {
			System.exit(0);
		
	}
	}
}

Did I miss the question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.