Witam. Moja "gra" umożliwia czatowanie między serwerem i klientem, jednak jest to skrypt napisany za pomocą jakiegoś tutoriala z YouTube'a. Niestety nie mam zielonego pojęcia jak przesyłać dane między serwerem a klientem np. po wciśnięciu przycisku.
Konkretnie chodzi mi o to, że gdy jeden gracz usiądzie do stołu w jednym z 4 miejsc, w jego oknie na miejsce buttona pojawia się jego imię (RamkaRysunku.b_1miejsce.setText(Gracz.imie);). Natomiast na ekranie drugiego gracza ma pojawić się ta sama informacja. Załóżmy, że siada serwer, a klientowi odbiera tą informację. Pomóżcie :(
Oto 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.Font;
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.DataInputStream;
import java.io.DataOutputStream;
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.io.Serializable;
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 ActionListener, Runnable
{
public void run() {
startRunning(ktoTo2);
}
static String gracz; // określany tylko raz
static JButton serverButton, clientButton;
static JButton b_1miejsce, b_2miejsce, b_3miejsce, b_4miejsce;
static JLabel stol, l_1, l_2, l_3, l_4, czat, l_1miejsce, l_2miejsce, l_3miejsce, l_4miejsce, komunikat;
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;
int size;
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,502,450,25);
add(userText, BorderLayout.NORTH); //!!!!!!!!!!!!!!!!!
l_1 = new JLabel("#1");
l_1.setFont(new Font("MS Sans Serif", Font.BOLD, 40));
l_1.setBounds(35, 0, 100, 100);
add(l_1);
l_2 = new JLabel("#2");
l_2.setFont(new Font("MS Sans Serif", Font.BOLD, 40));
l_2.setBounds(575, 0, 100, 100);
add(l_2);
//STOŁY i miejsca
stol = new JLabel("Stół graczy");
stol.setFont(new Font("MS Sans Serif", Font.BOLD, 24));
stol.setBounds(700, 25, 200, 40);
add(stol);
l_1miejsce = new JLabel("Miejsce #1");
l_1miejsce.setBounds(700, 70, 100, 40);
add(l_1miejsce);
l_2miejsce = new JLabel("Miejsce #2");
l_2miejsce.setBounds(900, 70, 100, 40);
add(l_2miejsce);
l_3miejsce = new JLabel("Miejsce #3");
l_3miejsce.setBounds(700, 150, 100, 40);
add(l_3miejsce);
l_3miejsce = new JLabel("Miejsce #4");
l_3miejsce.setBounds(900, 150, 100, 40);
add(l_3miejsce);
b_1miejsce = new JButton("Usiądź");
b_1miejsce.setBounds(700, 100, 150, 50);
add(b_1miejsce);
if(Gracz.gracz1Istnieje) // jeśli gracz siedzi przy stole...
{
b_1miejsce.setEnabled(false);
b_1miejsce.setText(Gracz.imie);
}
b_2miejsce = new JButton("Usiądź");
b_2miejsce.setBounds(900, 100, 150, 50);
add(b_2miejsce);
if(Gracz.gracz2Istnieje) // jeśli gracz siedzi przy stole...
{
b_2miejsce.setEnabled(false);
b_2miejsce.setText(Gracz.imie);
}
b_3miejsce = new JButton("Usiądź");
b_3miejsce.setBounds(700, 180, 150, 50);
add(b_3miejsce);
b_4miejsce = new JButton("Usiądź");
b_4miejsce.setBounds(900, 180, 150, 50);
add(b_4miejsce);
b_1miejsce.addActionListener(this);
b_2miejsce.addActionListener(this);
//Komunikaty
komunikat = new JLabel("");
komunikat.setBounds(700, 240, 500, 40);
komunikat.setForeground(Color.RED);
add(komunikat);
// Chat
czat = new JLabel("Chat");
czat.setFont(new Font("MS Sans Serif", Font.BOLD, 24));
czat.setBounds(680, 355, 200, 40);
add(czat);
chatWindow = new JTextArea();
add(new JScrollPane(chatWindow), BorderLayout.CENTER);
chatWindow.setBounds(680,400,450,100);
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
}
@Override
public void actionPerformed(ActionEvent ae) { // Przyciski "Usiądź"
Object zrodlo = ae.getSource();
if(zrodlo == b_1miejsce) {
Gracz gracz1 = new Gracz();
//wysłanie info do klienta
//wyslij("SIEDZE", 1, Gracz.imie); // co zrobił gracz, numer siedzenia, imie gracza
gracz = Gracz.imie;
Gracz.gracz1Istnieje = true;
RamkaRysunku.b_1miejsce.setEnabled(false);
RamkaRysunku.b_2miejsce.setEnabled(false);
RamkaRysunku.b_3miejsce.setEnabled(false);
RamkaRysunku.b_4miejsce.setEnabled(false);
RamkaRysunku.b_1miejsce.setText(Gracz.imie);
if(Gracz.gracz2Istnieje==true || Gracz.gracz3Istnieje==true || Gracz.gracz4Istnieje==true)
komunikat.setText("Zająłeś 1 miejsce przy stole.");
else
komunikat.setText("Zająłeś 1 miejsce przy stole. Zaczekaj na innych graczy.");
}
if(zrodlo == b_2miejsce) {
Gracz gracz2 = new Gracz();
gracz = Gracz.imie;
Gracz.gracz2Istnieje = true;
RamkaRysunku.b_1miejsce.setEnabled(false);
RamkaRysunku.b_2miejsce.setEnabled(false);
RamkaRysunku.b_3miejsce.setEnabled(false);
RamkaRysunku.b_4miejsce.setEnabled(false);
RamkaRysunku.b_2miejsce.setText(Gracz.imie);
if(Gracz.gracz1Istnieje==true || Gracz.gracz3Istnieje==true || Gracz.gracz4Istnieje==true)
komunikat.setText("Zająłeś 1 miejsce przy stole.");
else
komunikat.setText("Zająłeś 1 miejsce przy stole.\nZaczekaj na innych graczy.");
}
if(zrodlo == b_3miejsce) {
}
if(zrodlo == b_4miejsce) {
}
}
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("Czekam na innych graczy... \n");
connection = server.accept();
showMessage("Połączono z " + connection.getInetAddress().getHostName());
}
//client - connect to server
private void connectToServer() throws IOException{
showMessage("Nawiązywanie połączenia... \n");
connection = new Socket(InetAddress.getByName(serverIP), 6788);
showMessage("Połączono z "+ 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());
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
}
//during the chat conversation
private void whileChatting(String ktoTo) throws IOException{
if(ktoTo == "serwer")
{
String message = "Jesteś połączony!";
sendMessage(message,ktoTo);
ableToType(true);
do {
try {
message = (String) input.readObject();
showMessage("\n" + message);
}catch(ClassNotFoundException classNotFoundException){
showMessage("\nni dy rydy panie...!");
}
} 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 Zamykanie połączenia... \n");
ableToType(false);
try{
output.close();
input.close();
connection.close(); // zamyka socket
}catch(IOException ioException){
ioException.printStackTrace();
}
System.out.println(size);
}
//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 BŁĄD: NIE MOGĘ WYSŁAĆ WIADOMOŚCI ");
}
}
//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);
}
}
);
}
}
class Gracz
{
public static boolean gracz1Istnieje, gracz2Istnieje, gracz3Istnieje, gracz4Istnieje;
static String imie;
static int pionkow, oczek;
public Gracz()
{
imie = JOptionPane.showInputDialog("Podaj imię");
//JOptionPane.showMessageDialog(this, "Podaj imię: \n\n", "Podaj imię", JOptionPane.WARNING_MESSAGE);
pionkow = 4; oczek = 0;
}
public void main()
{
}
}
@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);
}
}