JavaFX Texture on each side of a box

How do I make a cube in javafx that have 6 different textures on each side of the cube?
The only way I know how to solve this, is by making 6 imageviews and give them each a specific coordinates that make them look like a cube.
Is there a other way to do this?
Like, I like to give the cube later on lighting, and some rotations. It will be more complex if I use this method.

Btw, I heard about Triangle Mesh, but I don't know how TextureCoords works.

handy links:
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/TriangleMesh.html
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Box.html

minify imageview setonmouseclicked code

How can I minify my code in here, I am giving each 23 total imageview a eventhandler.
code works, but I like to make the code shorter. I tried to use for loops to shorten the code.
here is a example what I tried to do:

    for (int i = 0 ; i < imgArrayList.size() ; i++) {
        imgArrayList.get(i).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                selectedTile = i;
            }
        });
    }

but it can't because, the "i" inside the handle method is final. I can't pass the "i" inside the handle method.

my goal is, that a specific imageview, that has for example ".get(3)", that needs to print out 3.
so if the imageview have a .get(i), it needs to print out the exact same number of i.
btw, the imageviews are stored in a arraylist, if you are curious where the ".get" comes from.

    protected static void addImageViewMouseEvents() {
        UI_SelectionMenu.imgArrayList.get(0).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 0;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(1).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 1;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(2).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 2;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(3).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 3;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(4).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 4;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(5).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 5;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(6).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 6;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(7).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 7;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(8).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 8;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(9).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 9;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(10).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 10;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(11).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 11;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(12).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 12;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(13).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 13;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(14).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 14;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(15).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 15;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(16).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 16;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(17).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 17;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(18).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 18;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(19).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 19;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(20).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 20;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(21).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 21;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
        UI_SelectionMenu.imgArrayList.get(22).setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                UI_SelectionMenu.selectedTile = 22;
                System.out.println(UI_SelectionMenu.selectedTile);
            }
        });
    }

JavaFX Smooth Key Events

I am making a ping pong game using JavaFX, but before I am going to make that, I like to test the KeyEvents.
I made a simple ping pong game about 2 years ago, but I like to improve my game.
And was pretty bad controlls back when I made the ping pong game, because of the not smooth controls.

so here is the problem:
whenever I holdpress A and switch quickly to holdpress D or D to A, same with (W to S and S to W).
it just takes a little break and then move, is there something I can change, improve?
I don't know why it does this.

JavaFX AudioSpectrumListener

So I am making a responsive audio waveform, if you don't know what that is, it is something like this: (btw this is my goal to make those audio waveforms).
https://i.ytimg.com/vi/J7uN-SQtOYI/maxresdefault.jpg
https://www.youtube.com/watch?v=OVMuwa-HRCQ
https://www.youtube.com/watch?v=SCD2tB1qILc
I don't know how to describe it, so just look at the videos and image.

but my question is, how do I get the values from the "AudioSpectrumListener", it has a lambda expression.
And I need the value of the magnitude. So I can print out the values.
Later I will use the values to make rectangles and that rectangles will change height shape because of the changing value from the magnitude.

I looked at some examples and tutorials, here are some:
jnlps://download.oracle.com/otndocs/products/javafx/8/samples/Ensemble/Ensemble.jnlp
https://victor-fx.blogspot.com/2017/08/audio-visualization-in-javafx.html

as you can see, I used animation timer, because the "AudioSpectrumInterval" is on 60, that means it updates 60 times in a second.
I can use a for a loop too, but it will print out the same values about a couple of times, or even more than that.

JavaFX TextField Append delay

So, I made a simple server-client chat program, but I have a problem:
if the server tries to message the client, the server lags or freezes a bit, same with the client.
is there something that I do wrong?

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Server extends Application {

    private Group serverGR;
    private Scene serverSC;
    private Stage window;
    private TextField tf;
    private TextArea ta;

    private ServerSocket ss;
    private Socket s;
    private DataInputStream dis;
    private DataOutputStream dos;

    ConnectionThread cT = new ConnectionThread();

    public void init() {
        cT.start();
    }

    @Override
    public void start(Stage primaryStage) {
        try {
        serverGR = new Group();
        serverSC = new Scene(serverGR, 800, 500, Color.LIGHTCYAN);
        window = primaryStage;
        window.setTitle("Bleidorb Simplistic ChatProgram \\\\\\\\\"ServerMode\"\\\\\\\\");
        window.setScene(serverSC);
        window.show();

        tf = new TextField();
        tf.setTranslateX(10);
        tf.setTranslateY(10);
        tf.setPrefWidth(400);
        tf.setPrefHeight(20);
        tf.appendText("Type your message here.");
        tf.setOnAction(event -> {

            String server = "Server: ";
            server += tf.getText();

                try {
                    dos.writeUTF(server);
                    dos.flush();
                    ta.appendText(dis.readUTF() + "\n");
                } catch (IOException e) {
                    e.printStackTrace();
                }

            tf.clear();

        });

        ta = new TextArea();
        ta.setTranslateX(10);
        ta.setTranslateY(40);
        ta.setPrefWidth(400);
        ta.setPrefHeight(400);

        serverGR.getChildren().addAll(tf, ta);
        } catch (Exception e) {
            System.out.println(e.toString() + "\n something wrong in startmethod, lol?");
        }
    }   

    @SuppressWarnings("deprecation")
    public void stop() {
        try {
            cT.stop();
            dis.close();
            ss.close();
            s.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }

    private class ConnectionThread extends Thread {

        @Override
        public void run(){
            try {
                ss = new ServerSocket(5279, 100);
                s = ss.accept();
                s.setTcpNoDelay(true);
                dis = new DataInputStream(s.getInputStream());
                dos = new DataOutputStream(s.getOutputStream());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Client extends Application {

    private Group serverGR;
    private Scene serverSC;
    private Stage window;
    private TextField tf;
    private TextArea ta;

    private Socket s;
    private DataInputStream dis;
    private DataOutputStream dos;

    ConnectionThread cT = new ConnectionThread();

    public void init() {
        cT.start();
    }

    @Override
    public void start(Stage primaryStage) {
        try {
        serverGR = new Group();
        serverSC = new Scene(serverGR, 800, 500, Color.LIGHTCYAN);
        window = primaryStage;
        window.setTitle("Bleidorb Simplistic ChatProgram \\\\\\\\\"ClientMode\"\\\\\\\\");
        window.setScene(serverSC);
        window.show();

        tf = new TextField();
        tf.setTranslateX(10);
        tf.setTranslateY(10);
        tf.setPrefWidth(400);
        tf.setPrefHeight(20);
        tf.appendText("Type your message here.");
        tf.setOnAction(event -> {

            String client = "Client: ";
            client += tf.getText();

                try {
                    dos.writeUTF(client);
                    dos.flush();
                    ta.appendText(dis.readUTF() + "\n");
                } catch (IOException e) {
                    e.printStackTrace();
                }

            tf.clear(); 

        });

        ta = new TextArea();
        ta.setTranslateX(10);
        ta.setTranslateY(40);
        ta.setPrefWidth(400);
        ta.setPrefHeight(400);

        serverGR.getChildren().addAll(tf, ta);
        } catch (Exception e) {
            System.out.println(e.toString() + "\n something wrong in startmethod, lol?");
        }
    }   

    @SuppressWarnings("deprecation")
    public void stop() {
        try {
            cT.stop();
            dos.close();
            s.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }

    private class ConnectionThread extends Thread {

        @Override
        public void run(){
            try {
                s = new Socket("localhost", 5279);
                s.setTcpNoDelay(true);
                dis = new DataInputStream(s.getInputStream());
                dos = new DataOutputStream(s.getOutputStream());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

JavaFX server client program

I am making a program, and I don't know why my program becomes unresponsive, when I click the button ):
I have a feeling its because of this:
"connection = server.accept();"
I don't know how to fix it.

I am trying to recreate this:
https://stackoverflow.com/questions/18505123/how-to-use-client-chat-on-different-pc

but in javafx.

package yeetYeet;

import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Server extends Application{

       private ObjectOutputStream output;
       private ObjectInputStream input;
       private ServerSocket server;
       private Socket connection;

    //set up and run the server
    private void startRunning() {
        try{
             server = new ServerSocket(6789, 100);

             new AnimationTimer() {

                @Override
                public void handle(long arg0) {
                    try{
                       waitForConnection();
                       setupStreams();
                       whileChatting();
                    }catch(EOFException eofException){
                       showMessage("\n Server ended the connection! ");
                    }catch (IOException IOException){
                        IOException.printStackTrace();
                    }finally{
                       closeCrap();
                    }
                }
             }.start();
          }catch(IOException ioException){
             ioException.printStackTrace();
          }
    }

    //wait for connection, then display connection information
    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();
        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 that user sent!");
            }
        }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();
        }catch(IOException ioException) {
            ioException.printStackTrace();
        }
    }

    //send a message to client
    private void sendMessage(String message) {
        try {
            output.writeObject("SERVER - " + message);
            output.flush();
            showMessage("\nSERVER - " + message);
        }catch(IOException ioException) {
            ta.appendText("\n ERROR: DUDE I CANT SEND THAT MESSAGE");
        }
    }

    //updates chatWindow
    private void showMessage(final String text) {
        new AnimationTimer() {

            @Override
            public void handle(long arg0) {
                ta.appendText(text);
            }
        }.start();
    }

    //let the user type stuff into their box
    private void ableToType(final boolean tof) {
        new AnimationTimer() {

            @Override
            public void handle(long arg0) {
                tf.setEditable(tof);
            }
        }.start();
    }

    private Group serverGR;
    private Scene serverSC;
    private Stage window;
    private TextField tf;
    private TextArea ta;
    private Button connectingStart;

    @Override
    public void start(Stage primaryStage) throws Exception {
        serverGR = new Group();
        serverSC = new Scene(serverGR, 1280, 720, Color.PALEGREEN);

        window = primaryStage;
        window.setScene(serverSC);
        window.setTitle("Bleidorb -\\\\\"Server\"\\\\- ChatProgram");
        window.show();

        tf = new TextField();
        tf.setTranslateX(10);
        tf.setTranslateY(10);
        tf.setPrefWidth(500);
        tf.setPrefHeight(20);
        tf.appendText("type your message here");
        serverGR.getChildren().add(tf);

        ta = new TextArea();
        ta.setTranslateX(10);
        ta.setTranslateY(40);
        ta.setPrefWidth(500);
        ta.setPrefHeight(500);
        serverGR.getChildren().add(ta);

        connectingStart = new Button("Connection Start");
        connectingStart.setTranslateX(600);
        connectingStart.setTranslateY(300);
        connectingStart.setPrefWidth(150);
        connectingStart.setPrefHeight(30);
        connectingStart.setOnAction(e -> {
            startRunning();
        });
        serverGR.getChildren().add(connectingStart);
    }

    public static void main(String[] args) {
        launch(args);
    }
}