Sockety i wyskakujące czarne okno (problem)

0

Witajcie

Mam taki problem, proszę o pomoc:

Piszę grę Chińczyka, która będzie umożliwiała granie przez sieć. Generalnie z samego działania gry nie mam nic, tylko planszę narysowaną za pomocą 2DGraphics i czat pomiędzy graczami (staram się napisać :D ). Zacznę od tego: istnieją 3 projekty (piszę w eclipse), pierwszy to Server, drugi Client, a trzeci Okno. Pisanie programu zacząłem od samego czatu, który napisałem według tutoriala. I żeby zobaczyć że DZIAŁA, należy umieścić kod z pliku Server.java i ServerTest.java w pierwszym projekcie, Client.java i ClientTest.java w drugim i odpalić kolejno pliki: ServerTest.java i ClientTest.java. Wszystko śmiga elegancko:

user image

Plik Okno.java to już osobny projekt, który nie korzysta z powyższych plików. Jest to okienko z wyborem typu gracza: Serwer/klient. Po wciśnięciu przycisku otwiera się nowy JFrame z JPanelem, na którym narysowałem planszę, a obok znajduje się czat, który ma tylko zmodyfikowany wygląd, a cały kod obsługujący go został skopiowany z poprzednich plików. Start socketów uruchamia metoda startRunning(). Większość kodu dla serwera i klienta pokrywa się, rożni się jedynie tym, że niezależnie od wciśniętego klawisza, nowy JFrame jest wywoływany z argumentami "127.0.0.1", ktoTo (pierwszy to argument jak dla klienta, a drugi to zmienna pomocnicza, która decyduje o wywoływaniu kolejnych metod...) - zresztą jak spojrzycie na pliki ClientTest.java i ServerTest.java, to zobaczycie o czym mówię, oraz kilkoma indywidualnymi metodami dla każdego z wybranego typu gracza.

Problem polega na tym, że przy starcie gry (np. po wciśnięciu przycisku Serwer) sockety są uruchamiane (za chwilę powiem skąd to wiem), ale okno maluje się prawie całe na czarno, a do tego niemożliwe jest jego normalne zamknięcie:

user image

user image

Problem oczywiście pojawił się w momencie, gdy do swojego okna z grą dołożyłem sockety. Wystarczy zakomentować linię

ramka.startRunning(ktoTo);

żeby zobaczyć planszę z gry. Co ciekawe, gdy klikniemy Serwer (ale bez zakomentowanej powyższej linii), a potem odpalimy plik ClientTest.java, widać, że połączenie serwer-klient jest aktywne,

user image

a po zamknięciu klienta nagle okno z grą się pojawia z informacją, że nastąpiło przerwanie połączenia.

user image

Jesli ktoś potrafi namierzyć źródło tego problemu to proszę o pomoc. Jestem trochę zielony w Javie i programowaniu obiektowym, dlatego dla mnie to trochę czarna magia, a komunikację między graczami muszę oddać już za tydzień :( Mój profesor nie za bardzo wie jak zaradzić mojemu problemowi, mówi tylko coś o odświeżaniu rysunku, ale bez konkretów.

Aha, i te dwa przyciski nad czatem do niczego nie służą, to pozostałość po wcześniejszej wersji gry!

Oto kody:

Server.java

package chicken;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Server extends JFrame {
    
    private JTextField userText;
    private JTextArea chatWindow;
    private ObjectOutputStream output;
    private ObjectInputStream input;
    
    private ServerSocket server;
    private Socket connection; // set up the Socket = set up the connection
    
    //konstruktor
    public Server()
    {
        super("Mój Komunikator");
        
        userText = new JTextField();
        userText.setEditable(false);
        userText.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        sendMessage(event.getActionCommand());
                        userText.setText(""); // po wciśnięciu ENTER'a mamy puste pole
                    }
                }
        );
        
        add(userText, BorderLayout.NORTH);
        chatWindow = new JTextArea();
        add(new JScrollPane(chatWindow));
        setSize(300,150);
        setVisible(true);
    }
    
    
    //set up and run the server
    public void startRunning() {
        
        try {
            
            server = new ServerSocket(6788, 100);
            while(true)
            {
                try{
                    // connect and have conversation
                    waitForConnection();
                    setupStreams();
                    whileChatting();
                }catch(EOFException oefException){
                    showMessage("\n Server ended the connection");
                }finally{
                    closeCrap();
                }
            }
            
        }catch(IOException ioException){
            ioException.printStackTrace();
        }
    }
    
    //wait for conn., then display connection info.
    private void waitForConnection() throws IOException{
          showMessage("Waiting for someone to connect... \n");
          connection = server.accept();
          showMessage("Now connected to " + connection.getInetAddress().getHostName());
                  
    }
    
    //get stream to send and receive data
    private void setupStreams() throws IOException{
        
        output = new ObjectOutputStream(connection.getOutputStream());
        
        output.flush(); //nie wiem co to
        
        input = new ObjectInputStream(connection.getInputStream());
        
        showMessage("\n Streams are now setup! \n");
        
    }
    
    //during the chat conversation
    private void whileChatting() throws IOException{
        
        String message = " You are now connected! ";
        sendMessage(message);
        
        ableToType(true);
        do {
            try {
                message = (String) input.readObject();
                showMessage("\n" + message);
            }catch(ClassNotFoundException classNotFoundException){
                showMessage("\n idk wtf theh user send!");
            }
        } while(!message.equals("CLIENT - END"));
        
    }
    
    //close streams and sockets after you are done chatting
    private void closeCrap(){
        
        showMessage("\n Closing connections... \n");
        ableToType(false);
        try{
            output.close();
            input.close();
            connection.close(); // zamyka socket
        }catch(IOException ioException){
            ioException.printStackTrace();
        }
    }
    
    //send a message to client
    private void sendMessage(String message){
        try{
            output.writeObject("SERVER - " + message);
            output.flush();
            showMessage("\n SERVER - " + message);
        }catch(IOException ioException){
            chatWindow.append("\n ERROR: DUDE I CANT SEND THAT MESSAGE ");
        }
    }
    
    //updates chatWindow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    private void showMessage(final String text){
        
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        chatWindow.append(text);
                    }
                }
        );
        
    }
    
    //let the users type stuff into their box
    private void ableToType(final boolean tof){
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        userText.setEditable(tof);
                    }
                }
        );
    }
    
}

ServerTest.java

package chicken;
import javax.swing.JFrame;
/**
 *
 * @author Chicken
 */
public class ServerTest {
    public static void main(String[] args) {
        Server sally = new Server();
        sally.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sally.startRunning();
    }
}

Client.java

package chicken;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Client extends JFrame {

    private JTextField userText;
    private JTextArea chatWindow;
    private ObjectOutputStream output;
    private ObjectInputStream input;
        
    private String message = "";
    private String serverIP;
    private Socket connection;
    //konstruktor
    public Client(String host)
    {
        super("Client mofo!");
        serverIP = host;
        userText = new JTextField();
        userText.setEditable(false);
        userText.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent event){
                        sendMessage(event.getActionCommand());
                        userText.setText("");
                    }
                }
        );
        
        add(userText, BorderLayout.NORTH);
        chatWindow = new JTextArea();
        add(new JScrollPane(chatWindow), BorderLayout.CENTER);
        setSize(300,150);
        setVisible(true);
        
    }
    
    //connect to server
    public void startRunning(){
        try{
            
            connectToServer();
            setupStreams();
            whileChatting();
        }catch(EOFException eofException){
            showMessage("\n Client terminated connection");
        }catch(IOException ioException){
            ioException.printStackTrace();
        }finally{
            closeCrap();
        }
    }
    
    //connect to server
    private void connectToServer() throws IOException{
        
        showMessage("Attepting connection... \n");
        connection = new Socket(InetAddress.getByName(serverIP), 6788);
        
        showMessage("Connected to: "+ connection.getInetAddress().getHostName());
                
    }
    
    //set up streams to send and receive messages
    private void setupStreams() throws IOException{
        output = new ObjectOutputStream(connection.getOutputStream());
        output.flush();
        input = new ObjectInputStream(connection.getInputStream());
        showMessage("\n Dude your streams are now good to go! \n");
    }
    
    //while chatting with server
    private void whileChatting() throws IOException{
        ableToType(true);
        do{
            try{
                message = (String) input.readObject();
                showMessage("\n" + message);
            }catch(ClassNotFoundException classNotFoundException){
                showMessage("\n I don't know that object type!");
            }
                
        }while(!message.equals("SERVER - END"));
    }
    
    //close the streams and sockets
    private void closeCrap(){
        showMessage("\n closing crap down...");
        ableToType(false);
        
        try{
            output.close();
            input.close();
            connection.close();
        }catch(IOException ioException)
        {
            ioException.printStackTrace();
        }
    }
    
    //send message to server
    private void sendMessage(String message){
        try{
            output.writeObject("CLIENT - " + message);
            output.flush();
            showMessage("\n CLIENT - " + message);
        }catch(IOException ioException){
            chatWindow.append("\n ERROR: DUDE I CANT SEND THAT MESSAGE ");
        }
    }
    
    //updates chatWindow
    private void showMessage(final String text){
        
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        chatWindow.append(text);
                    }
                }
        );
        
    }
    
    //gives user permission to type crap into the text box
    private void ableToType(final boolean tof){
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        userText.setEditable(tof);
                    }
                }
        );
    }
    
    
    
    public static void main(String[] args) {
        
        
        
    }
    
}

ClientTest.java

package chicken;

import javax.swing.JFrame;

public class ClientTest {
    public static void main(String[] args) {
        
        Client charlie;
        charlie = new Client("127.0.0.1"); // localhost - serwer jest na tym samym komputerze co klient! ;)
        charlie.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        charlie.startRunning();
    }
}

Okno.java

package chicken;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints; 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.*;
import java.awt.Color;
import javax.swing.*;

import java.io.BufferedReader;  
import java.io.EOFException;
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;  
import java.net.InetAddress;
import java.net.ServerSocket;  
import java.net.Socket; 
/**
 *
 * @author Chicken
 */
@SuppressWarnings("serial")
public class Okno extends JFrame implements ActionListener {	
	
	JButton bServer, bClient;
	static String ktoTo = "";

	public Okno()
	{
		bServer = new JButton("Serwer");
		bClient = new JButton("Klient");
		
		setLayout(null); 
		setTitle("Chińczyk by Kamil Derkacz - EKRAN STARTOWY"); 
		setSize(400,400);
		setVisible(true);
		
		bServer.setBounds(0, 0, 100, 40);
    	bClient.setBounds(100, 0, 100, 40);
    	add(bServer);
    	add(bClient);
    	bServer.addActionListener(this);
    	bClient.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent ae) { // to co się dzieje po wciśnięciu przycisków! :))
		
		Object zrodlo = ae.getSource();
		
		if(zrodlo == bServer){
			
			ktoTo = "serwer";
			System.out.println("Wybrales"+ktoTo);
			stworzRamke(ktoTo);
		}
		else if(zrodlo == bClient){
			
			ktoTo = "klient";
			System.out.println("Wybrales "+ktoTo);
			stworzRamke(ktoTo);
		}
        
	}
	
    public static void main(String[] args)
	{
    	Okno okienko = new Okno();
    	okienko.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	okienko.setVisible(true);
		
	}
    
    public static void stworzRamke(String ktoTo) {
    	
    	RamkaRysunku ramka = new RamkaRysunku("127.0.0.1", ktoTo);
		ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
		ramka.setVisible(true); 
		ramka.startRunning(ktoTo);
    }
}



@SuppressWarnings("serial")
class RamkaRysunku extends JFrame
{
	
	JButton serverButton, clientButton;
	
	
	private JTextField userText;
    private JTextArea chatWindow;
    
    private ObjectOutputStream output;
    private ObjectInputStream input;
    
    private ServerSocket server;
    private Socket connection; // set up the Socket = set up the connection
    
    //klient
    private String message = "";
    private String serverIP;
    
    
    //konstruktor
	public RamkaRysunku(String host, String ktoTo) 
	{
		super("A");
		serverIP = host;
		
		
		setLayout(null); // dzięki temu możemy określać współrzędne bzwzględne
		
		userText = new JTextField();
        userText.setEditable(false);
        userText.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        sendMessage(event.getActionCommand());
                        userText.setText(""); // po wciśnięciu ENTER'a mamy puste pole
                    }
                }
        );
        
        userText.setBounds(680,352,450,25);
        add(userText, BorderLayout.NORTH); //!!!!!!!!!!!!!!!!!
        
        
        //przyciski
        serverButton = new JButton("Serwer");
        serverButton.setBounds(800, 50, 100, 40);
        add(serverButton);
        
        clientButton = new JButton("Klient");
        clientButton.setBounds(940, 50, 100, 40);
        add(clientButton);
        
        //serverButton.addActionListener(this);
        //clientButton.addActionListener(this);
        
        
        //okno komunikatów
        chatWindow = new JTextArea();
        add(new JScrollPane(chatWindow), BorderLayout.CENTER);
        chatWindow.setBounds(680,150,450,200);
        add(chatWindow, BorderLayout.NORTH);
        setVisible(true);
        
		//setTitle("Chińczyk by Kamil Derkacz"); 
		setSize(1200,700);
		
		PanelRysunku panel = new PanelRysunku(); 
		panel.setBounds(0,0,700,700);
		Container zawartosc = getContentPane();
		
		zawartosc.add(panel); // Dodanie panelu do kontenera
		
	}



	//set up and run the server
    public void startRunning(String ktoTo) {
        System.out.println("Jestem w startRunnin: "+ktoTo);
    	if(ktoTo == "serwer")
    	{
    	
	        try {
		            server = new ServerSocket(6788, 100); // port, liczba uż.
		            while(true)
		            {
		                try{
		                    // connect and have conversation
		                    waitForConnection();
		                    setupStreams();
		                    whileChatting(ktoTo);
		                }catch(EOFException oefException){
		                    showMessage("\n Server ended the connection");
		                }finally{
		                    closeCrap();
		                }
		            }
	        }catch(IOException ioException){
	            ioException.printStackTrace();
	        }
        
    	}
    	else if(ktoTo == "klient")
    	{
    		try{
                connectToServer();
                setupStreams();
                whileChatting(ktoTo);
            }catch(EOFException eofException){
                showMessage("\n Client terminated connection");
            }catch(IOException ioException){
                ioException.printStackTrace();
            }finally{
                closeCrap();
            }
    	}
    }
    
    
    //wait for conn., then display connection info.
    private void waitForConnection() throws IOException{
          showMessage("Waiting for someone to connect... \n");
          connection = server.accept();
          showMessage("Now connected to " + connection.getInetAddress().getHostName());
    }
    
    //client - connect to server
    private void connectToServer() throws IOException{
        showMessage("Attepting connection... \n");
        connection = new Socket(InetAddress.getByName(serverIP), 6788);
        showMessage("Connected to: "+ connection.getInetAddress().getHostName());
    }
    
    
    //get stream to send and receive data
    private void setupStreams() throws IOException{
        output = new ObjectOutputStream(connection.getOutputStream());
        output.flush(); //nie wiem
        input = new ObjectInputStream(connection.getInputStream());
        showMessage("\n Streams are now setup! \n");
    }
    
    //during the chat conversation
    private void whileChatting(String ktoTo) throws IOException{
        if(ktoTo == "serwer")
        {
	        String message = " You are now connected! ";
	        sendMessage(message);
	        
	        ableToType(true);
	        do {
	            try {
	                message = (String) input.readObject();
	                showMessage("\n" + message);
	            }catch(ClassNotFoundException classNotFoundException){
	                showMessage("\n idk wtf theh user send!");
	            }
	        } while(!message.equals("CLIENT - END"));
        }
        else if(ktoTo == "klient")
        {
        	ableToType(true);
            do{
                try{
                    message = (String) input.readObject();
                    showMessage("\n" + message);
                }catch(ClassNotFoundException classNotFoundException){
                    showMessage("\n I don't know that object type!");
                }
                    
            }while(!message.equals("SERVER - END"));
        }
    }
    
    //close streams and sockets after you are done chatting
    private void closeCrap(){
        
        showMessage("\n Closing connections... \n");
        ableToType(false);
        try{
            output.close();
            input.close();
            connection.close(); // zamyka socket
        }catch(IOException ioException){
            ioException.printStackTrace();
        }
    }
    
    //send a message to client
    private void sendMessage(String message){
        try{
            output.writeObject(message);
            output.flush();
            showMessage(message);
        }catch(IOException ioException){
            chatWindow.append("\n ERROR: DUDE I CANT SEND THAT MESSAGE ");
        }
    }
    
    //updates chatWindow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    private void showMessage(final String text){
        
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        chatWindow.append(text);
                    }
                }
        );
        
    }
    
    //let the users type stuff into their box
    private void ableToType(final boolean tof){
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        userText.setEditable(tof);
                    }
                }
        );
    }
	
	
}











@SuppressWarnings("serial")
class PanelRysunku extends JPanel  // Deklaracja klasy "PanelRysunku" dziedziczącej po klasie JPanel
{
	
	public void paintComponent(Graphics g)  // Utworzenie metody paintComponent
	{
            super.paintComponent(g); // Czyszczenie obrazu
        
            GeneralPath srodek = new GeneralPath(GeneralPath.WIND_EVEN_ODD); // Stworzenie obiektu klasy GeneralPath
            BasicStroke linia1 = new BasicStroke(30f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // Stworzenie linii klasy BasicStroke i określenie jej właściwości: grubości oraz zaokrągleń krawędzi
            BasicStroke linia2 = new BasicStroke(20f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // ...
            BasicStroke linia3 = new BasicStroke(0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER); // ...

            Graphics2D g2 = (Graphics2D)g; //
            Graphics2D g3 = (Graphics2D)g; // 
            Graphics2D g4 = (Graphics2D)g; // 
            Graphics2D g6 = (Graphics2D)g; // 
                                           // Stworzenie obiektów graficznych g
            Graphics2D g7 = (Graphics2D)g; // 
            Graphics2D g8 = (Graphics2D)g; // 
            Graphics2D g9 = (Graphics2D)g; // 
            Graphics2D g10 = (Graphics2D)g; // 

            g2.setColor(Color.RED); // Ustawienie koloru 1 linii
            g2.setStroke(linia1); // Nadanie ustawień linii

            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Włączenie anty-aliasingu
            g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // Włączenie renderingu

            Point2D.Double p1 = new Point2D.Double(195, 50); //
            Point2D.Double p2 = new Point2D.Double(50, 283); // Utworzenie punktów trójkąta
            Point2D.Double p3 = new Point2D.Double(330, 283);//
            Line2D.Double l1 = new Line2D.Double(p1, p2); //
            Line2D.Double l2 = new Line2D.Double(p2, p3); // Połączenie punktów liniami
            Line2D.Double l3 = new Line2D.Double(p3, p1); //
            g2.draw(l1); //
            g2.draw(l2); // Narysowanie figury
            g2.draw(l3); //

            g3.setColor(Color.YELLOW); // Ustawienie koloru 2 linii
            g3.setStroke(linia2); // Nadanie ustawień linii
            Point2D.Double p4 = new Point2D.Double(195, 60); //
            Point2D.Double p5 = new Point2D.Double(60, 278); // Utworzenie punktów trójkąta
            Point2D.Double p6 = new Point2D.Double(320, 278);//
            Line2D.Double  l4 = new Line2D.Double(p4, p5); //
            Line2D.Double  l5 = new Line2D.Double(p5, p6); // Połączenie punktów liniami
            Line2D.Double  l6 = new Line2D.Double(p6, p4); //
            srodek.append(l4, true); //
            srodek.append(l5, true); // Dodanie linii do obiektu "srodek"
            srodek.append(l6, true); //
            g3.fill(srodek); // Wypełnienie obiektu "srodek"
            g3.draw(l4); //
            g3.draw(l5); // Narysowanie figury
            g3.draw(l6); //
        
		
  
	    Rectangle2D prost1 = new Rectangle2D.Double(160, 120, 25, 65); // Deklaracja prostokąta wraz z określeniem położenia i wymiarów
	    g6.setStroke(linia3); // Ustawienie grubości linii prostokąta wcześniej zdefiniowaną linią nr 3
	    g6.setColor(Color.black); // Kolor figury
	    g6.fill(prost1); // Wypełenienie figury
	    g6.draw(prost1); // Narysowanie figury
	    
	    Rectangle2D prost2 = new Rectangle2D.Double(200, 120, 25, 65);
	    g7.setStroke(linia3); 
	    g7.setColor(Color.black);
	    g7.fill(prost2);
	    g7.draw(prost2);
	    
	    Rectangle2D prost3 = new Rectangle2D.Double(136, 200, 25, 70);
	    g8.setStroke(linia3);
	    g8.setColor(Color.black);
	    g8.fill(prost3);
	    g8.draw(prost3);
	    
	    Rectangle2D prost4 = new Rectangle2D.Double(225, 200, 25, 70);
	    g9.setStroke(linia3);
	    g9.setColor(Color.black);
	    g9.fill(prost4);
	    g9.draw(prost4);
	    
	    int n = 4; // Deklaracja zmiennej odpowiadającej liczbie wierzchołków równoległoboku
	    int x_rown1[] = {136, 160, 185, 160}; // Punkty X równoległoboku
	    int y_rown1[] = {200, 180, 184, 205}; // Punkty Y równoległoboku
	    g4.setColor(Color.black); // Ustawienie koloru figury
	    g4.fillPolygon(x_rown1, y_rown1, n); // Wypełnienie figury złożonej z powyższych punktów o "n" wierzchołkach
	    
	    int x_rown2[] = {200, 225, 250, 225}; //
	    int y_rown2[] = {185, 180, 200, 205}; //
	    g4.setColor(Color.black);  			  // Narysowanie drugiej figury 
	    g4.fillPolygon(x_rown2, y_rown2, n);  //
            
            
            
            
            //Plansza-Obrys
            Rectangle2D planszaObrys = new Rectangle2D.Double(25, 25, 604, 604);
	    g10.setStroke(linia3);
	    g10.setColor(Color.black);
	    g10.fill(planszaObrys);
	    g10.draw(planszaObrys);
            //Plansza-wypełnienie
            Rectangle2D planszaWypel = new Rectangle2D.Double(27, 27, 600, 600);
	    g10.setStroke(linia3);
	    g10.setColor(Color.GREEN);
	    g10.fill(planszaWypel);
	    g10.draw(planszaWypel);
            
            //Czarny-Krzyż
            g10.setColor(Color.BLACK);
            Rectangle2D kolumnaPion = new Rectangle2D.Double(251, 46, 151, 551);
            g10.fill(kolumnaPion);g10.draw(kolumnaPion);
            Rectangle2D kolumnaPozi = new Rectangle2D.Double(51, 246, 551, 151);
            g10.fill(kolumnaPozi);g10.draw(kolumnaPozi);
            
            
            //Pola
            g10.setColor(Color.GRAY);
            //wzór:
            Rectangle2D pole = new Rectangle2D.Double(252, 547, 49, 49);
            g10.fill(pole);g10.draw(pole);
            //
            Rectangle2D pole1 = new Rectangle2D.Double(252, 47, 49, 49);
            g10.fill(pole1);g10.draw(pole1);
            Rectangle2D pole2 = new Rectangle2D.Double(252, 97, 49, 49);
            g10.fill(pole2);g10.draw(pole2);
            Rectangle2D pole3 = new Rectangle2D.Double(252, 147, 49, 49);
            g10.fill(pole3);g10.draw(pole3);
            Rectangle2D pole4 = new Rectangle2D.Double(252, 197, 49, 49);
            g10.fill(pole4);g10.draw(pole4);
            Rectangle2D pole5 = new Rectangle2D.Double(252, 247, 49, 49);
            g10.fill(pole5);g10.draw(pole5);
            
            Rectangle2D pole6 = new Rectangle2D.Double(252, 347, 49, 49);
            g10.fill(pole6);g10.draw(pole6);
            Rectangle2D pole7 = new Rectangle2D.Double(252, 397, 49, 49);
            g10.fill(pole7);g10.draw(pole7);
            Rectangle2D pole8 = new Rectangle2D.Double(252, 447, 49, 49);
            g10.fill(pole8);g10.draw(pole8);
            Rectangle2D pole9 = new Rectangle2D.Double(252, 497, 49, 49);
            g10.fill(pole9);g10.draw(pole9);
            Rectangle2D pole10 = new Rectangle2D.Double(252, 547, 49, 49);
            g10.fill(pole10);g10.draw(pole10);
            
            //pole przed bazą u góry^
            Rectangle2D pole11 = new Rectangle2D.Double(302, 47, 49, 49);
            g10.fill(pole11);g10.draw(pole11);
            Rectangle2D pole12 = new Rectangle2D.Double(302, 547, 49, 49);
            g10.fill(pole12);g10.draw(pole12);
            
            Rectangle2D pole13 = new Rectangle2D.Double(352, 47, 49, 49);
            g10.fill(pole13);g10.draw(pole13);
            Rectangle2D pole14 = new Rectangle2D.Double(352, 97, 49, 49);
            g10.fill(pole14);g10.draw(pole14);
            Rectangle2D pole15 = new Rectangle2D.Double(352, 147, 49, 49);
            g10.fill(pole15);g10.draw(pole15);
            Rectangle2D pole16 = new Rectangle2D.Double(352, 197, 49, 49);
            g10.fill(pole16);g10.draw(pole16);
            Rectangle2D pole17 = new Rectangle2D.Double(352, 247, 49, 49);
            g10.fill(pole17);g10.draw(pole17);
            
            Rectangle2D pole18 = new Rectangle2D.Double(352, 347, 49, 49);
            g10.fill(pole18);g10.draw(pole18);
            Rectangle2D pole19 = new Rectangle2D.Double(352, 397, 49, 49);
            g10.fill(pole19);g10.draw(pole19);
            Rectangle2D pole20 = new Rectangle2D.Double(352, 447, 49, 49);
            g10.fill(pole20);g10.draw(pole20);
            Rectangle2D pole21 = new Rectangle2D.Double(352, 497, 49, 49);
            g10.fill(pole21);g10.draw(pole21);
            Rectangle2D pole22 = new Rectangle2D.Double(352, 547, 49, 49);
            g10.fill(pole22);g10.draw(pole22);
            
            
            
            Rectangle2D pole23 = new Rectangle2D.Double(52, 247, 49, 49);
            g10.fill(pole23);g10.draw(pole23);
            Rectangle2D pole24 = new Rectangle2D.Double(102, 247, 49, 49);
            g10.fill(pole24);g10.draw(pole24);
            Rectangle2D pole25 = new Rectangle2D.Double(152, 247, 49, 49);
            g10.fill(pole25);g10.draw(pole25);
            Rectangle2D pole26 = new Rectangle2D.Double(202, 247, 49, 49);
            g10.fill(pole26);g10.draw(pole26);
            
            
            Rectangle2D pole27 = new Rectangle2D.Double(402, 247, 49, 49);
            g10.fill(pole27);g10.draw(pole27);
            Rectangle2D pole28 = new Rectangle2D.Double(452, 247, 49, 49);
            g10.fill(pole28);g10.draw(pole28);
            Rectangle2D pole29 = new Rectangle2D.Double(502, 247, 49, 49);
            g10.fill(pole29);g10.draw(pole29);
            Rectangle2D pole30 = new Rectangle2D.Double(552, 247, 49, 49);
            g10.fill(pole30);g10.draw(pole30);
            
            Rectangle2D pole31 = new Rectangle2D.Double(52, 297, 49, 49);
            g10.fill(pole31);g10.draw(pole31);
            Rectangle2D pole32 = new Rectangle2D.Double(552, 297, 49, 49);
            g10.fill(pole32);g10.draw(pole32);
            
            Rectangle2D pole33 = new Rectangle2D.Double(52, 347, 49, 49);
            g10.fill(pole33);g10.draw(pole33);
            Rectangle2D pole34 = new Rectangle2D.Double(102, 347, 49, 49);
            g10.fill(pole34);g10.draw(pole34);
            Rectangle2D pole35 = new Rectangle2D.Double(152, 347, 49, 49);
            g10.fill(pole35);g10.draw(pole35);
            Rectangle2D pole36 = new Rectangle2D.Double(202, 347, 49, 49);
            g10.fill(pole36);g10.draw(pole36);
        
            Rectangle2D pole37 = new Rectangle2D.Double(402, 347, 49, 49);
            g10.fill(pole37);g10.draw(pole37);
            Rectangle2D pole38 = new Rectangle2D.Double(452, 347, 49, 49);
            g10.fill(pole38);g10.draw(pole38);
            Rectangle2D pole39 = new Rectangle2D.Double(502, 347, 49, 49);
            g10.fill(pole39);g10.draw(pole39);
            Rectangle2D pole40 = new Rectangle2D.Double(552, 347, 49, 49);
            g10.fill(pole40);g10.draw(pole40);
            
            
            //Domki-graczy
            g10.setColor(Color.GRAY);
            g10.fillOval(76, 76, 150, 150);
            g10.fillOval(426, 76, 150, 150);
            g10.fillOval(76, 421, 150, 150); // duże koła
            g10.fillOval(426, 421, 150, 150);
            
            //pionki
            int pol_pionk1[][] = { { 101, 101 }, { 151, 101 }, { 101, 151 }, { 151, 151 } };
            int pol_pionk2[][] = { { 451, 101 }, { 501, 101 }, { 451, 151 }, { 501, 151 } };
            int pol_pionk3[][] = { { 101, 446 }, { 151, 446 }, { 101, 496 }, { 151, 496 } };
            int pol_pionk4[][] = { { 451, 446 }, { 501, 446 }, { 451, 496 }, { 501, 496 } };
            
            g10.setColor(Color.BLUE);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk1[i][0], pol_pionk1[i][1], 48, 48);
            g10.setColor(Color.GREEN);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk2[i][0], pol_pionk2[i][1], 48, 48);
            g10.setColor(Color.YELLOW);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk3[i][0], pol_pionk3[i][1], 48, 48);
            g10.setColor(Color.RED);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk4[i][0], pol_pionk4[i][1], 48, 48);
            
            
            
            //Bazy
            g10.setColor(Color.BLUE);
            Rectangle2D baza11 = new Rectangle2D.Double(302, 97, 49, 49);
            g10.fill(baza11);g10.draw(baza11);
            Rectangle2D baza12 = new Rectangle2D.Double(302, 147, 49, 49);
            g10.fill(baza12);g10.draw(baza12);
            Rectangle2D baza13 = new Rectangle2D.Double(302, 197, 49, 49);
            g10.fill(baza13);g10.draw(baza13);
            Rectangle2D baza14 = new Rectangle2D.Double(302, 247, 49, 49);
            g10.fill(baza14);g10.draw(baza14);
            g10.setColor(Color.GREEN);
            Rectangle2D baza21 = new Rectangle2D.Double(502, 297, 49, 49);
            g10.fill(baza21);g10.draw(baza21);
            Rectangle2D baza22 = new Rectangle2D.Double(452, 297, 49, 49);
            g10.fill(baza22);g10.draw(baza22);
            Rectangle2D baza23 = new Rectangle2D.Double(402, 297, 49, 49);
            g10.fill(baza23);g10.draw(baza23);
            Rectangle2D baza24 = new Rectangle2D.Double(352, 297, 49, 49);
            g10.fill(baza24);g10.draw(baza24);
            g10.setColor(Color.RED);
            Rectangle2D baza31 = new Rectangle2D.Double(302, 497, 49, 49);
            g10.fill(baza31);g10.draw(baza31);
            Rectangle2D baza32 = new Rectangle2D.Double(302, 447, 49, 49);
            g10.fill(baza32);g10.draw(baza32);
            Rectangle2D baza33 = new Rectangle2D.Double(302, 397, 49, 49);
            g10.fill(baza33);g10.draw(baza33);
            Rectangle2D baza34 = new Rectangle2D.Double(302, 347, 49, 49);
            g10.fill(baza34);g10.draw(baza34);
            g10.setColor(Color.YELLOW);
            Rectangle2D baza41 = new Rectangle2D.Double(102, 297, 49, 49);
            g10.fill(baza41);g10.draw(baza41);
            Rectangle2D baza42 = new Rectangle2D.Double(152, 297, 49, 49);
            g10.fill(baza42);g10.draw(baza42);
            Rectangle2D baza43 = new Rectangle2D.Double(202, 297, 49, 49);
            g10.fill(baza43);g10.draw(baza43);
            Rectangle2D baza44 = new Rectangle2D.Double(252, 297, 49, 49);
            g10.fill(baza44);g10.draw(baza44);
            
            
	}
	
	
	
}

Pozdrawiam!

0
while(true)
            {
                try{
                    // connect and have conversation
                    waitForConnection();
                    setupStreams();
                    whileChatting();
                }catch(EOFException oefException){
                    showMessage("\n Server ended the connection");
                }finally{
                    closeCrap();
                }
            }

Ta pętla będzie się wykonywać ciągle, a więc po nawiązaniu połączenia iteracja zacznie od nowa i znów będzie czekać na połączenie ;/.
Pamiętaj o wykorzystywaniu wielowątkowości przy korzystaniu z gniazd, ponieważ gdy będzie czekało na odbiór jakieś wiadomości to pochłonie cały wątek :P.

1
  1. jw, robisz coś w wątku GUI więc będzie wisiał. Musisz takie operacje wykonywać w innym wątku
  2. Twoje paintComponent to WTF tygodnia, jeśli nie miesiąca. Odpowiedz sam sobie: ile zajęłoby ci powiększenie planszy, powiedzmy o połowę. A teraz wyobraź sobie że użytkownik nie moze się zdecydować i chciałby zobaczyć kilka przykładowych rozmiarów... Moja rada? Wywal to paintComponent i napisz od nowa, tym razem z głową...
    Szczególnie że plansza powinna być częścią modelu gry i malowanie planszy powinno sprowadzać sie do plansza.narysujSie(). To co zrobiłeś jest zupełnie bez sensu i nijak nie podepniesz do tego jakiejkolwiek gry.
0

Dzięki, poczytam o wielowątkowości i postaram się coś wymyślić. A ty Shalom wyluzuj, bo ci klawiatura padnie...

0

Nie ma co wymyślać : jeden wątek do interfejsu (czyli GUI), drugi wątek do odbierania wiadomości i wyświetlania ich.
Warto też podczas łączenia tworzysz tymczasowo jeden wątek,który będzie czekał na połączenie, potem zaś go usunąć :P.

0

A więc udało mi się utworzyć 2 wątki: pierwszy dla czatu (klasa RamkaRysunku - może nie jest to logiczne, ale działa :) ), a drugi dla interfejsu (klasa PanelRysunku).

Wszystko działa! :)

**Kandif ** - zechcesz zerknąć do kodu czy wszystko jest jak należy (chodzi mi głównie o same wątki)?

Kod:

package chicken;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints; 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.*;
import java.awt.Color;
import javax.swing.*;

import java.io.BufferedReader;  
import java.io.EOFException;
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;  
import java.net.InetAddress;
import java.net.ServerSocket;  
import java.net.Socket; 
/**
 *
 * @author Chicken
 */



@SuppressWarnings("serial")
public class Okno extends JFrame implements ActionListener  {		
	
	JButton bServer, bClient;
	static String ktoTo = "";

	public Okno()
	{
		bServer = new JButton("Serwer");
		bClient = new JButton("Klient");
		
		setLayout(null); 
		setTitle("Chińczyk by Kamil Derkacz - EKRAN STARTOWY"); 
		setSize(400,400);
		setVisible(true);
		
		bServer.setBounds(0, 0, 100, 40);
    	bClient.setBounds(100, 0, 100, 40);
    	add(bServer);
    	add(bClient);
    	bServer.addActionListener(this);
    	bClient.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent ae) { // to co się dzieje po wciśnięciu przycisków! :))
		
		Object zrodlo = ae.getSource();
		
		if(zrodlo == bServer){
			
			ktoTo = "serwer";
			System.out.println("Wybrales"+ktoTo);
			stworzRamke(ktoTo);
		}
		else if(zrodlo == bClient){
			
			ktoTo = "klient";
			System.out.println("Wybrales "+ktoTo);
			stworzRamke(ktoTo);
		}
        
	}
	
    public static void main(String[] args)
	{
    	Okno okienko = new Okno();
    	okienko.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	okienko.setVisible(true);
	}
    
    public static void stworzRamke(String ktoTo) {
    	
    	RamkaRysunku ramka = new RamkaRysunku("127.0.0.1", ktoTo);
    	(new Thread(ramka)).start(); /////////////////////////////////////////
    	
		ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
		ramka.setVisible(true);
		
    }
}



@SuppressWarnings("serial")
class RamkaRysunku extends JFrame implements Runnable
{
	
	public void run() {
		startRunning(ktoTo2);
	}
	
	JButton serverButton, clientButton;
	
	
	private JTextField userText;
    private JTextArea chatWindow;
    private ObjectOutputStream output;
    private ObjectInputStream input;
    private ServerSocket server;
    private Socket connection; // set up the Socket = set up the connection
    //klient
    private String message = "";
    private String serverIP;
    
    static String ktoTo2 = ""; ////////////////////////////////////
    
    //konstruktor
	public RamkaRysunku(String host, final String ktoTo) 
	{
		super("A");
		serverIP = host;
		ktoTo2 = ktoTo;
		
		setLayout(null); // dzięki temu możemy określać współrzędne bzwzględne
		
		userText = new JTextField();
        userText.setEditable(false);
        userText.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        sendMessage(event.getActionCommand(), ktoTo);
                        userText.setText(""); // po wciśnięciu ENTER'a mamy puste pole
                    }
                }
        );
        
        userText.setBounds(680,352,450,25);
        add(userText, BorderLayout.NORTH); //!!!!!!!!!!!!!!!!!
        
        
        //przyciski
        serverButton = new JButton("Serwer");
        serverButton.setBounds(800, 50, 100, 40);
        add(serverButton);
        
        clientButton = new JButton("Klient");
        clientButton.setBounds(940, 50, 100, 40);
        add(clientButton);
        
        //serverButton.addActionListener(this);
        //clientButton.addActionListener(this);
        
        
        //okno komunikatów
        chatWindow = new JTextArea();
        add(new JScrollPane(chatWindow), BorderLayout.CENTER);
        chatWindow.setBounds(680,150,450,200);
        add(chatWindow, BorderLayout.NORTH);
        setVisible(true);
        
		//setTitle("Chińczyk by Kamil Derkacz"); 
		setSize(1200,700);
		
		PanelRysunku panel = new PanelRysunku(); 
		(new Thread(panel)).start(); /////////////////////////////////////////
		
		panel.setBounds(0,0,700,700);
		Container zawartosc = getContentPane();
		zawartosc.add(panel); // dodanie panelu do kontenera
		
	}

	
    public void startRunning(String ktoTo) { //set up and run the server
        System.out.println("Jestem w startRunnin: "+ktoTo);
    	if(ktoTo == "serwer")
    	{
    	
	        try {
		            server = new ServerSocket(6788, 100); // port, liczba uż.
		            while(true)
		            {
		                try{
		                    // connect and have conversation
		                    waitForConnection();
		                    setupStreams();
		                    whileChatting(ktoTo);
		                }catch(EOFException oefException){
		                    showMessage("\n Server ended the connection");
		                }finally{
		                    closeCrap();
		                }
		            }
	        }catch(IOException ioException){
	            ioException.printStackTrace();
	        }
        
    	}
    	else if(ktoTo == "klient")
    	{
    		try{
                connectToServer();
                setupStreams();
                whileChatting(ktoTo);
            }catch(EOFException eofException){
                showMessage("\n Client terminated connection");
            }catch(IOException ioException){
                ioException.printStackTrace();
            }finally{
                closeCrap();
            }
    	}
    }
    
    
    //wait for conn., then display connection info.
    private void waitForConnection() throws IOException{
          showMessage("Waiting for someone to connect... \n");
          connection = server.accept();
          showMessage("Now connected to " + connection.getInetAddress().getHostName());
    }
    
    //client - connect to server
    private void connectToServer() throws IOException{
        showMessage("Attepting connection... \n");
        connection = new Socket(InetAddress.getByName(serverIP), 6788);
        showMessage("Connected to: "+ connection.getInetAddress().getHostName());
    }
    
    
    //get stream to send and receive data
    private void setupStreams() throws IOException{
        output = new ObjectOutputStream(connection.getOutputStream());
        output.flush(); //nie wiem
        input = new ObjectInputStream(connection.getInputStream());
        showMessage("\n Streams are now setup! \n");
    }
    
    //during the chat conversation
    private void whileChatting(String ktoTo) throws IOException{
        if(ktoTo == "serwer")
        {
	        String message = " You are now connected! ";
	        sendMessage(message,ktoTo);
	        
	        ableToType(true);
	        do {
	            try {
	                message = (String) input.readObject();
	                showMessage("\n" + message);
	            }catch(ClassNotFoundException classNotFoundException){
	                showMessage("\n idk wtf theh user send!");
	            }
	        } while(!message.equals("klient - END"));
        }
        else if(ktoTo == "klient")
        {
        	ableToType(true);
            do{
                try{
                    message = (String) input.readObject();
                    showMessage("\n" + message);
                }catch(ClassNotFoundException classNotFoundException){
                    showMessage("\n I don't know that object type!");
                }
                    
            }while(!message.equals("serwer - END"));
        }
    }
    
    //close streams and sockets after you are done chatting
    private void closeCrap(){
        
        showMessage("\n Closing connections... \n");
        ableToType(false);
        try{
            output.close();
            input.close();
            connection.close(); // zamyka socket
        }catch(IOException ioException){
            ioException.printStackTrace();
        }
    }
    
    //send a message to client
    private void sendMessage(String message, String ktoTo){
        try{
            output.writeObject(ktoTo + " - " + message);
            output.flush();
            showMessage("\n" + ktoTo + " - " + message);
        }catch(IOException ioException){
            chatWindow.append("\n ERROR: DUDE I CANT SEND THAT MESSAGE ");
        }
    }
    
    //updates chatWindow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    private void showMessage(final String text){
        
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        chatWindow.append(text);
                    }
                }
        );
        
    }
    
    //let the users type stuff into their box
    private void ableToType(final boolean tof){
        SwingUtilities.invokeLater(
                new Runnable(){
                    public void run(){
                        userText.setEditable(tof);
                    }
                }
        );
    }
	
	
}











@SuppressWarnings("serial")
class PanelRysunku extends JPanel
	implements Runnable
{
	
	@Override
    public void run() {
		paintComponent(null);
	}
	
	public void paintComponent(Graphics g)  // Utworzenie metody paintComponent
	{
            super.paintComponent(g); // Czyszczenie obrazu
        
            GeneralPath srodek = new GeneralPath(GeneralPath.WIND_EVEN_ODD); // Stworzenie obiektu klasy GeneralPath
            BasicStroke linia1 = new BasicStroke(30f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // Stworzenie linii klasy BasicStroke i określenie jej właściwości: grubości oraz zaokrągleń krawędzi
            BasicStroke linia2 = new BasicStroke(20f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // ...
            BasicStroke linia3 = new BasicStroke(0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER); // ...

            Graphics2D g2 = (Graphics2D)g; //
            Graphics2D g3 = (Graphics2D)g; // 
            Graphics2D g4 = (Graphics2D)g; // 
            Graphics2D g6 = (Graphics2D)g; // 
                                           // Stworzenie obiektów graficznych g
            Graphics2D g7 = (Graphics2D)g; // 
            Graphics2D g8 = (Graphics2D)g; // 
            Graphics2D g9 = (Graphics2D)g; // 
            Graphics2D g10 = (Graphics2D)g; // 

            g2.setColor(Color.RED); // Ustawienie koloru 1 linii
            g2.setStroke(linia1); // Nadanie ustawień linii

            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Włączenie anty-aliasingu
            g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // Włączenie renderingu

            Point2D.Double p1 = new Point2D.Double(195, 50); //
            Point2D.Double p2 = new Point2D.Double(50, 283); // Utworzenie punktów trójkąta
            Point2D.Double p3 = new Point2D.Double(330, 283);//
            Line2D.Double l1 = new Line2D.Double(p1, p2); //
            Line2D.Double l2 = new Line2D.Double(p2, p3); // Połączenie punktów liniami
            Line2D.Double l3 = new Line2D.Double(p3, p1); //
            g2.draw(l1); //
            g2.draw(l2); // Narysowanie figury
            g2.draw(l3); //

            g3.setColor(Color.YELLOW); // Ustawienie koloru 2 linii
            g3.setStroke(linia2); // Nadanie ustawień linii
            Point2D.Double p4 = new Point2D.Double(195, 60); //
            Point2D.Double p5 = new Point2D.Double(60, 278); // Utworzenie punktów trójkąta
            Point2D.Double p6 = new Point2D.Double(320, 278);//
            Line2D.Double  l4 = new Line2D.Double(p4, p5); //
            Line2D.Double  l5 = new Line2D.Double(p5, p6); // Połączenie punktów liniami
            Line2D.Double  l6 = new Line2D.Double(p6, p4); //
            srodek.append(l4, true); //
            srodek.append(l5, true); // Dodanie linii do obiektu "srodek"
            srodek.append(l6, true); //
            g3.fill(srodek); // Wypełnienie obiektu "srodek"
            g3.draw(l4); //
            g3.draw(l5); // Narysowanie figury
            g3.draw(l6); //
        
		
  
	    Rectangle2D prost1 = new Rectangle2D.Double(160, 120, 25, 65); // Deklaracja prostokąta wraz z określeniem położenia i wymiarów
	    g6.setStroke(linia3); // Ustawienie grubości linii prostokąta wcześniej zdefiniowaną linią nr 3
	    g6.setColor(Color.black); // Kolor figury
	    g6.fill(prost1); // Wypełenienie figury
	    g6.draw(prost1); // Narysowanie figury
	    
	    Rectangle2D prost2 = new Rectangle2D.Double(200, 120, 25, 65);
	    g7.setStroke(linia3); 
	    g7.setColor(Color.black);
	    g7.fill(prost2);
	    g7.draw(prost2);
	    
	    Rectangle2D prost3 = new Rectangle2D.Double(136, 200, 25, 70);
	    g8.setStroke(linia3);
	    g8.setColor(Color.black);
	    g8.fill(prost3);
	    g8.draw(prost3);
	    
	    Rectangle2D prost4 = new Rectangle2D.Double(225, 200, 25, 70);
	    g9.setStroke(linia3);
	    g9.setColor(Color.black);
	    g9.fill(prost4);
	    g9.draw(prost4);
	    
	    int n = 4; // Deklaracja zmiennej odpowiadającej liczbie wierzchołków równoległoboku
	    int x_rown1[] = {136, 160, 185, 160}; // Punkty X równoległoboku
	    int y_rown1[] = {200, 180, 184, 205}; // Punkty Y równoległoboku
	    g4.setColor(Color.black); // Ustawienie koloru figury
	    g4.fillPolygon(x_rown1, y_rown1, n); // Wypełnienie figury złożonej z powyższych punktów o "n" wierzchołkach
	    
	    int x_rown2[] = {200, 225, 250, 225}; //
	    int y_rown2[] = {185, 180, 200, 205}; //
	    g4.setColor(Color.black);  			  // Narysowanie drugiej figury 
	    g4.fillPolygon(x_rown2, y_rown2, n);  //
            
            
            
            
            //Plansza-Obrys
            Rectangle2D planszaObrys = new Rectangle2D.Double(25, 25, 604, 604);
	    g10.setStroke(linia3);
	    g10.setColor(Color.black);
	    g10.fill(planszaObrys);
	    g10.draw(planszaObrys);
            //Plansza-wypełnienie
            Rectangle2D planszaWypel = new Rectangle2D.Double(27, 27, 600, 600);
	    g10.setStroke(linia3);
	    g10.setColor(Color.GREEN);
	    g10.fill(planszaWypel);
	    g10.draw(planszaWypel);
            
            //Czarny-Krzyż
            g10.setColor(Color.BLACK);
            Rectangle2D kolumnaPion = new Rectangle2D.Double(251, 46, 151, 551);
            g10.fill(kolumnaPion);g10.draw(kolumnaPion);
            Rectangle2D kolumnaPozi = new Rectangle2D.Double(51, 246, 551, 151);
            g10.fill(kolumnaPozi);g10.draw(kolumnaPozi);
            
            
            //Pola
            g10.setColor(Color.GRAY);
            //wzór:
            Rectangle2D pole = new Rectangle2D.Double(252, 547, 49, 49);
            g10.fill(pole);g10.draw(pole);
            //
            Rectangle2D pole1 = new Rectangle2D.Double(252, 47, 49, 49);
            g10.fill(pole1);g10.draw(pole1);
            Rectangle2D pole2 = new Rectangle2D.Double(252, 97, 49, 49);
            g10.fill(pole2);g10.draw(pole2);
            Rectangle2D pole3 = new Rectangle2D.Double(252, 147, 49, 49);
            g10.fill(pole3);g10.draw(pole3);
            Rectangle2D pole4 = new Rectangle2D.Double(252, 197, 49, 49);
            g10.fill(pole4);g10.draw(pole4);
            Rectangle2D pole5 = new Rectangle2D.Double(252, 247, 49, 49);
            g10.fill(pole5);g10.draw(pole5);
            
            Rectangle2D pole6 = new Rectangle2D.Double(252, 347, 49, 49);
            g10.fill(pole6);g10.draw(pole6);
            Rectangle2D pole7 = new Rectangle2D.Double(252, 397, 49, 49);
            g10.fill(pole7);g10.draw(pole7);
            Rectangle2D pole8 = new Rectangle2D.Double(252, 447, 49, 49);
            g10.fill(pole8);g10.draw(pole8);
            Rectangle2D pole9 = new Rectangle2D.Double(252, 497, 49, 49);
            g10.fill(pole9);g10.draw(pole9);
            Rectangle2D pole10 = new Rectangle2D.Double(252, 547, 49, 49);
            g10.fill(pole10);g10.draw(pole10);
            
            //pole przed bazą u góry^
            Rectangle2D pole11 = new Rectangle2D.Double(302, 47, 49, 49);
            g10.fill(pole11);g10.draw(pole11);
            Rectangle2D pole12 = new Rectangle2D.Double(302, 547, 49, 49);
            g10.fill(pole12);g10.draw(pole12);
            
            Rectangle2D pole13 = new Rectangle2D.Double(352, 47, 49, 49);
            g10.fill(pole13);g10.draw(pole13);
            Rectangle2D pole14 = new Rectangle2D.Double(352, 97, 49, 49);
            g10.fill(pole14);g10.draw(pole14);
            Rectangle2D pole15 = new Rectangle2D.Double(352, 147, 49, 49);
            g10.fill(pole15);g10.draw(pole15);
            Rectangle2D pole16 = new Rectangle2D.Double(352, 197, 49, 49);
            g10.fill(pole16);g10.draw(pole16);
            Rectangle2D pole17 = new Rectangle2D.Double(352, 247, 49, 49);
            g10.fill(pole17);g10.draw(pole17);
            
            Rectangle2D pole18 = new Rectangle2D.Double(352, 347, 49, 49);
            g10.fill(pole18);g10.draw(pole18);
            Rectangle2D pole19 = new Rectangle2D.Double(352, 397, 49, 49);
            g10.fill(pole19);g10.draw(pole19);
            Rectangle2D pole20 = new Rectangle2D.Double(352, 447, 49, 49);
            g10.fill(pole20);g10.draw(pole20);
            Rectangle2D pole21 = new Rectangle2D.Double(352, 497, 49, 49);
            g10.fill(pole21);g10.draw(pole21);
            Rectangle2D pole22 = new Rectangle2D.Double(352, 547, 49, 49);
            g10.fill(pole22);g10.draw(pole22);
            
            
            
            Rectangle2D pole23 = new Rectangle2D.Double(52, 247, 49, 49);
            g10.fill(pole23);g10.draw(pole23);
            Rectangle2D pole24 = new Rectangle2D.Double(102, 247, 49, 49);
            g10.fill(pole24);g10.draw(pole24);
            Rectangle2D pole25 = new Rectangle2D.Double(152, 247, 49, 49);
            g10.fill(pole25);g10.draw(pole25);
            Rectangle2D pole26 = new Rectangle2D.Double(202, 247, 49, 49);
            g10.fill(pole26);g10.draw(pole26);
            
            
            Rectangle2D pole27 = new Rectangle2D.Double(402, 247, 49, 49);
            g10.fill(pole27);g10.draw(pole27);
            Rectangle2D pole28 = new Rectangle2D.Double(452, 247, 49, 49);
            g10.fill(pole28);g10.draw(pole28);
            Rectangle2D pole29 = new Rectangle2D.Double(502, 247, 49, 49);
            g10.fill(pole29);g10.draw(pole29);
            Rectangle2D pole30 = new Rectangle2D.Double(552, 247, 49, 49);
            g10.fill(pole30);g10.draw(pole30);
            
            Rectangle2D pole31 = new Rectangle2D.Double(52, 297, 49, 49);
            g10.fill(pole31);g10.draw(pole31);
            Rectangle2D pole32 = new Rectangle2D.Double(552, 297, 49, 49);
            g10.fill(pole32);g10.draw(pole32);
            
            Rectangle2D pole33 = new Rectangle2D.Double(52, 347, 49, 49);
            g10.fill(pole33);g10.draw(pole33);
            Rectangle2D pole34 = new Rectangle2D.Double(102, 347, 49, 49);
            g10.fill(pole34);g10.draw(pole34);
            Rectangle2D pole35 = new Rectangle2D.Double(152, 347, 49, 49);
            g10.fill(pole35);g10.draw(pole35);
            Rectangle2D pole36 = new Rectangle2D.Double(202, 347, 49, 49);
            g10.fill(pole36);g10.draw(pole36);
        
            Rectangle2D pole37 = new Rectangle2D.Double(402, 347, 49, 49);
            g10.fill(pole37);g10.draw(pole37);
            Rectangle2D pole38 = new Rectangle2D.Double(452, 347, 49, 49);
            g10.fill(pole38);g10.draw(pole38);
            Rectangle2D pole39 = new Rectangle2D.Double(502, 347, 49, 49);
            g10.fill(pole39);g10.draw(pole39);
            Rectangle2D pole40 = new Rectangle2D.Double(552, 347, 49, 49);
            g10.fill(pole40);g10.draw(pole40);
            
            
            //Domki-graczy
            g10.setColor(Color.GRAY);
            g10.fillOval(76, 76, 150, 150);
            g10.fillOval(426, 76, 150, 150);
            g10.fillOval(76, 421, 150, 150); // duże koła
            g10.fillOval(426, 421, 150, 150);
            
            //pionki
            int pol_pionk1[][] = { { 101, 101 }, { 151, 101 }, { 101, 151 }, { 151, 151 } };
            int pol_pionk2[][] = { { 451, 101 }, { 501, 101 }, { 451, 151 }, { 501, 151 } };
            int pol_pionk3[][] = { { 101, 446 }, { 151, 446 }, { 101, 496 }, { 151, 496 } };
            int pol_pionk4[][] = { { 451, 446 }, { 501, 446 }, { 451, 496 }, { 501, 496 } };
            
            g10.setColor(Color.BLUE);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk1[i][0], pol_pionk1[i][1], 48, 48);
            g10.setColor(Color.GREEN);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk2[i][0], pol_pionk2[i][1], 48, 48);
            g10.setColor(Color.YELLOW);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk3[i][0], pol_pionk3[i][1], 48, 48);
            g10.setColor(Color.RED);
            for(int i=0; i<4; i++)
                g10.fillOval(pol_pionk4[i][0], pol_pionk4[i][1], 48, 48);
            
            
            
            //Bazy
            g10.setColor(Color.BLUE);
            Rectangle2D baza11 = new Rectangle2D.Double(302, 97, 49, 49);
            g10.fill(baza11);g10.draw(baza11);
            Rectangle2D baza12 = new Rectangle2D.Double(302, 147, 49, 49);
            g10.fill(baza12);g10.draw(baza12);
            Rectangle2D baza13 = new Rectangle2D.Double(302, 197, 49, 49);
            g10.fill(baza13);g10.draw(baza13);
            Rectangle2D baza14 = new Rectangle2D.Double(302, 247, 49, 49);
            g10.fill(baza14);g10.draw(baza14);
            g10.setColor(Color.GREEN);
            Rectangle2D baza21 = new Rectangle2D.Double(502, 297, 49, 49);
            g10.fill(baza21);g10.draw(baza21);
            Rectangle2D baza22 = new Rectangle2D.Double(452, 297, 49, 49);
            g10.fill(baza22);g10.draw(baza22);
            Rectangle2D baza23 = new Rectangle2D.Double(402, 297, 49, 49);
            g10.fill(baza23);g10.draw(baza23);
            Rectangle2D baza24 = new Rectangle2D.Double(352, 297, 49, 49);
            g10.fill(baza24);g10.draw(baza24);
            g10.setColor(Color.RED);
            Rectangle2D baza31 = new Rectangle2D.Double(302, 497, 49, 49);
            g10.fill(baza31);g10.draw(baza31);
            Rectangle2D baza32 = new Rectangle2D.Double(302, 447, 49, 49);
            g10.fill(baza32);g10.draw(baza32);
            Rectangle2D baza33 = new Rectangle2D.Double(302, 397, 49, 49);
            g10.fill(baza33);g10.draw(baza33);
            Rectangle2D baza34 = new Rectangle2D.Double(302, 347, 49, 49);
            g10.fill(baza34);g10.draw(baza34);
            g10.setColor(Color.YELLOW);
            Rectangle2D baza41 = new Rectangle2D.Double(102, 297, 49, 49);
            g10.fill(baza41);g10.draw(baza41);
            Rectangle2D baza42 = new Rectangle2D.Double(152, 297, 49, 49);
            g10.fill(baza42);g10.draw(baza42);
            Rectangle2D baza43 = new Rectangle2D.Double(202, 297, 49, 49);
            g10.fill(baza43);g10.draw(baza43);
            Rectangle2D baza44 = new Rectangle2D.Double(252, 297, 49, 49);
            g10.fill(baza44);g10.draw(baza44);
            
            
	}
	
	
	
}


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