Rysowanie / klambury sieciowe

0

Musze zrobic kalambury sieciowe. Mam napisany serwer, klienta, klient watek i rysowanie ale nie wiem jak połączyć rysowanie z resztą. Chodzi o to że jak otwieram nowego klienta to żeby wyskakiwało nowe okienko z rysowaniem. Bardzo proszę o pomoc. Oto kody źródłowe:

SERWER


import java.io.*;
import java.net.*;
 
public class serwer {
 
    static Socket klientSocket = null;
    static ServerSocket serwerSocket = null;
    static klientwatek klienci[] = new klientwatek[4];
 
    public static void main(String args[]) {
 
        int numerPortu = 2500;
 
        try {
            serwerSocket = new ServerSocket(numerPortu);
                } 
 
        catch (IOException e) {
            System.out.println(e);
        }
 
        while (true) {
            try {
                klientSocket = serwerSocket.accept(); 
                for (int idx = 0; idx <= 3; idx++) {
                    if (klienci[idx] == null) {
                        (klienci[idx] = new klientwatek(klientSocket, klienci)).start();  
                         break;
                    }
                }
           } catch (IOException e) {
               System.out.println(e);
            }
        }
    }
}
KLIENT


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JApplet;
 
public class klient implements Runnable{
 
    static Socket klientSocket = null;
    static PrintStream outputStream = null; 
    static DataInputStream inputStream = null; 
    static BufferedReader inputLine = null;
    static boolean zamkniety = false;
    
 
    public static void main(String[] args) {
 
        int numerPortu = 2500;
 
        String host = "localhost";
 
        try {
            klientSocket = new Socket(host, numerPortu);
            inputLine = new BufferedReader(new InputStreamReader(System.in));
            outputStream = new PrintStream(klientSocket.getOutputStream());
            inputStream = new DataInputStream(klientSocket.getInputStream());
            
            } 
 
        catch (UnknownHostException e) {
                e.printStackTrace();
        }
 
        catch (IOException e) {
                e.printStackTrace();
        }
 
 
        if (klientSocket != null && outputStream != null && inputStream != null) {
            try {
 
                new Thread(new klient()).start();
             
                while (!zamkniety) {
                    outputStream.println(inputLine.readLine());
                }
 
                outputStream.close();
                inputStream.close();
                klientSocket.close();
 
            } catch (IOException e) {
                    e.printStackTrace();
            }
        }
    }
 
    public void run() {
        String odpowiedzi;
 
        try {
            while ((odpowiedzi = inputStream.readLine()) != null) {
               System.out.println(odpowiedzi);
            }
            zamkniety = true;
                }   
        catch (IOException e) {
                e.printStackTrace();
        }        
   }
}

KLIENT WATEK


import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
 
class klientwatek extends Thread  {
 
    DataInputStream inputStream = null; 
    PrintStream outputStream = null; 
    Socket klientSocket = null;
    klientwatek klienci[];
    
    
 
    public klientwatek(Socket klientSocket, klientwatek[] klienci) {
        this.klientSocket = klientSocket;
        this.klienci = klienci;
    }
 
    public void run() {
        String linia;
        String nick;
        try {
            inputStream = new DataInputStream(klientSocket.getInputStream());
            outputStream = new PrintStream(klientSocket.getOutputStream());
 
            outputStream.println("Podaj nick");
            
            nick = inputStream.readLine(); 
            
            while (true) {
                linia = inputStream.readLine();
                   if (linia.startsWith("/out")) {
                   break; 
              }
                for (int idx = 0; idx <= 3; idx++) {
                    if (klienci[idx] != null) {
                        klienci[idx].outputStream.println("<" + nick + "> " + linia);
                    }
                }
            }
           for (int idx = 0; idx <= 3; idx++) {
                if (klienci[idx] == this) {
                    klienci[idx] = null;
                }
            }
 
            inputStream.close();
            outputStream.close();
            klientSocket.close();
        } catch (IOException e) {
        };
        
    }


	
}

 RYSOWANIE

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.Serializable;

import javax.swing.JApplet;
 
public class okienko extends JApplet implements MouseMotionListener, MouseListener
{
 
int x=0; int y=0; int a=0;
public void init()
{
addMouseMotionListener(this); addMouseListener(this);
}
 
public void mouseMoved (MouseEvent e) {}
public void mouseDragged(MouseEvent e) {
 
if (a==1)
{
x=e.getX();
y=e.getY();
getGraphics().setColor(Color.BLACK); getGraphics().fillOval(x,y,5,5);
}
}
public void mouseClicked (MouseEvent e)
{
int button = e.getButton();
if (button == MouseEvent.BUTTON3) {repaint();}
}
public void mouseEntered (MouseEvent e){}
public void mouseExited (MouseEvent e){}
public void mousePressed (MouseEvent e){
int button = e.getButton();
if (button == MouseEvent.BUTTON3) {a=0; repaint();}
if (button == MouseEvent.BUTTON1) {a=1;}
}
public void mouseReleased(MouseEvent e){}
 
public void paint(Graphics g)
{
g.setColor(Color.white); g.fillRect(0,0,420,240);
}
}
 
0

up

up

1 użytkowników online, w tym zalogowanych: 0, gości: 1