SHARE
TWEET

Untitled

a guest Jan 29th, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package client;
  2.  
  3. import javafx.event.ActionEvent;
  4. import javafx.fxml.FXML;
  5. import javafx.scene.control.Alert;
  6. import javafx.scene.control.Button;
  7.  
  8. import javax.swing.*;
  9. import java.io.*;
  10. import java.net.Socket;
  11.  
  12. public class Controller {
  13.     @FXML
  14.     public Button b00, b01, b02, b10, b11, b12, b20, b21, b22;
  15.     private Button[] arr;
  16.     private Socket socket;
  17.     private BufferedReader bufferedReader;
  18.  
  19.     public static boolean sign; //true - X false - O
  20.     public static boolean move;
  21.  
  22.     public void initialize() {
  23.         System.out.println("Initialize method");
  24.         arr = new Button[]{b00, b01, b02, b10, b11, b12, b20, b21, b22};
  25. //        this.socket = ClientMain.socket;
  26. //        try {
  27. //            this.bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  28. //        } catch (IOException e) {
  29. //            e.printStackTrace();
  30. //        }
  31.         System.out.println(move);
  32.         for (Button b : arr) {
  33.             b.setOnAction((e) -> {
  34.                 butclick(e);
  35.                 char[] c = new char[arr.length];
  36.                 for (int i = 0; i < arr.length; i++) {
  37.                     c[i] = arr[i].getText().charAt(0);
  38.                     System.out.println(c[i]);
  39.                 }
  40.                 String result = "XOOOOXXXO";
  41.                 //String result = sendRequest(new String(c));
  42.  
  43.  
  44.                     if(result.equals("win")){
  45.  
  46.                     }
  47.                     else if (result.equals("lost")){
  48.  
  49.                     }
  50.                     else if (result.equals("tie")){
  51.  
  52.                     }
  53.                     else{
  54.                         for(int i =0; i < arr.length;i++){
  55.                             arr[i].setText(result.charAt(i)+"");
  56.                         }
  57.                     }
  58.                 Alert alert = new Alert(Alert.AlertType.INFORMATION);
  59.                 alert.setTitle("REMIS");
  60.                 alert.setHeaderText("Niestety nie udało ci sie wygrać");
  61.                 alert.setContentText("Powodzenia nastepnym razem");
  62.                 alert.showAndWait();
  63.             });
  64.         }
  65.     }
  66.  
  67.     public void butclick(ActionEvent e) {
  68.         ((Button) e.getSource()).setText(sign ? "X" : "O");
  69.     }
  70.  
  71.  
  72.     private String sendRequest(String request) {
  73.         System.out.println("Creating request");
  74.         PrintWriter printWriter;
  75.         String response;
  76.         try {
  77.             printWriter = new PrintWriter(socket.getOutputStream());
  78.         } catch (IOException e) {
  79.             e.printStackTrace();
  80.             return request;
  81.         }
  82.  
  83.         printWriter.println(request);
  84.         printWriter.flush();
  85.         System.out.println("Send request");
  86.         try {
  87.             this.bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  88.             System.out.println("New bufferedReader");
  89.             response = this.bufferedReader.readLine();
  90.             System.out.println(response);
  91.         } catch (IOException e) {
  92.             e.printStackTrace();
  93.             return request;
  94.         }
  95.         return request;
  96.     }
  97. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top