yes, that is the problem

//here is my code

import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class SmoothKeyEvents extends Application {

    public final static String TITLE = "simple key-input program";
    public final static short WIDTH = 1280;
    public final static short HEIGHT = 720;

    private Stage window;
    private Scene mainS;
    private Group groupS;
    private Rectangle rect;

    private int x = 50;
    private int y = 50;
    private int velX = 0;
    private int velY = 0;

    @Override
    public void start(Stage primaryStage) {
        groupS = new Group();
        mainS = new Scene(groupS, WIDTH, HEIGHT, Color.DARKBLUE);
        window = primaryStage;
        window.setScene(mainS);
        window.setTitle(TITLE);
        window.show();
        window.requestFocus();

        rect = new Rectangle();
        rect.setFill(Color.MEDIUMSPRINGGREEN);
        rect.setX(x);
        rect.setY(y);
        rect.setWidth(150);
        rect.setHeight(150);
        groupS.getChildren().add(rect);

        mainS.setOnKeyPressed(new EventHandler<KeyEvent>(){

            @Override
            public void handle(KeyEvent ke) {
                if(ke.getCode() == KeyCode.A) {
                    setVelX(-9);
                }
                if(ke.getCode() == KeyCode.S) {
                    setVelY(9);
                }
                if(ke.getCode() == KeyCode.D) {
                    setVelX(9);
                }
                if(ke.getCode() == KeyCode.W) {
                    setVelY(-9);
                }
            }
        });

        mainS.setOnKeyReleased(new EventHandler<KeyEvent>(){

            @Override
            public void handle(KeyEvent ke) {
                if(ke.getCode() == KeyCode.A) {
                    setVelX(0);             
                }
                if(ke.getCode() == KeyCode.S) {
                    setVelY(0);
                }
                if(ke.getCode() == KeyCode.D) {
                    setVelX(0);
                }
                if(ke.getCode() == KeyCode.W) {
                    setVelY(0);
                }
            }
        });

        final AnimationTimer at = new AnimationTimer() {

            @Override
            public void handle(long arg0) {
                x += velX;
                rect.setX(x);
                y += velY;
                rect.setY(y);
            }
        };
        at.start();
    }

    public void setVelX(int velX) {
        this.velX = velX;
    }

    public void setVelY(int velY) {
        this.velY = velY;
    }

    public void stop() {
        System.out.println("program exited");
    }

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

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.

how can I make it that another client can join in?
like there is 2 clients and 1 server.
do I just copy the clients code?

Nailed it :D

package com.VINSTORM.bleidorb.AudioWaveFormFX_V1.v_aa;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.AudioSpectrumListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class AWF_FX_v5 extends Application implements AudioSpectrumListener {

    public final static String TITLE = "AWF special program";
    public final static short WIDTH = 1280;
    public final static short HEIGHT = 720;
    public static String AUDIO_FILE = "../mp3Music/Cynematic - Waterbased.mp3";
    public static String AUDIO_FILE1 = "../mp3Music/AcerDroid -Skies.mp3";
    public static String AUDIO_FILE2 = "../mp3Music/Capturez - Patterns.mp3";
    public static String AUDIO_FILE3 = "../mp3Music/Kanooli - Instinct.mp3";
    public static String AUDIO_FILE4 = "../mp3Music/RavenKreyn_InTheAir_NCSrelease.mp3";
    public static String AUDIO_URI = AWF_FX_v1.class.getResource(AUDIO_FILE1).toExternalForm();

    private Stage window;
    private Scene mainS;
    private Group groupS;
    private MediaPlayer audioMP;
    private float[] cMag;
    private short power = 5;

    private Rectangle[] rect = new Rectangle[40];

    @Override
    public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) {
        for (int i = 0; i < magnitudes.length; i++) {
            cMag = magnitudes;
            cMag[i] = (int) cMag[i] * power;
            System.out.println("cMag (" + i + "): " + cMag[i]);
        }

        for(int i = 0; i < rect.length; i++) {
            rect[i].setY(500 + ((cMag[i] + (60 * power)) * -1));
            rect[i].setHeight(50 + (cMag[i] + (60 * power)));
        }
    }

    @Override
    public void start(Stage primaryStage) {
        groupS = new Group();
        mainS = new Scene(groupS, WIDTH, HEIGHT, Color.DARKBLUE);
        window = primaryStage;
        window.setScene(mainS);
        window.setTitle(TITLE);
        window.show();

        Media audioMedia = new Media(AUDIO_URI);
        audioMP = new MediaPlayer(audioMedia);
        audioMP.play();
        audioMP.setCycleCount(MediaPlayer.INDEFINITE);
        audioMP.setVolume(0.02);
        audioMP.setAudioSpectrumInterval(0.01);
        audioMP.setAudioSpectrumNumBands(40);
        audioMP.setAudioSpectrumListener(this);

        for(int i = 0; i < rect.length; i++) {
            rect[i] = new Rectangle();
            rect[i].setX(250 + (i * 20));
            rect[i].setY(500);
            rect[i].setWidth(10);
            rect[i].setHeight(50); ...

code without that comments lines:

package com.VINSTORM.bleidorb.AudioWaveFormFX_V1.v_aa;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.AudioSpectrumListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class AWF_FX_v1 extends Application implements AudioSpectrumListener {

    public final static String TITLE = "AWF special program";
    public final static short WIDTH = 1280;
    public final static short HEIGHT = 720;
    public static String AUDIO_FILE = "../mp3Music/Cynematic - Waterbased.mp3";
    public static String AUDIO_FILE1 = "../mp3Music/AcerDroid -Skies.mp3";
    public static String AUDIO_FILE2 = "../mp3Music/Capturez - Patterns.mp3";
    public static String AUDIO_FILE3 = "../mp3Music/Kanooli - Instinct.mp3";
    public static String AUDIO_FILE4 = "../mp3Music/RavenKreyn_InTheAir_NCSrelease.mp3";
    public static String AUDIO_URI = AWF_FX_v1.class.getResource(AUDIO_FILE2).toExternalForm();

    private Stage window;
    private Scene mainS;
    private Group groupS;
    private MediaPlayer audioMP;
    private float[] cMag;

    private Rectangle[] rect = new Rectangle[8];

    @Override
    public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) {
        for (int i = 0; i < magnitudes.length; i++) {
            cMag = magnitudes;
            cMag[i] = (int) cMag[i];
        }
        for(int i = 0; i < rect.length; i++) {
            rect[i].setY(310 + ((cMag[i] + 60) * -1));
            rect[i].setHeight(50 + (cMag[i] + 60));
            System.out.println(i + " setY: " + rect[i].getY());
            System.out.println(i + " setHeight " + rect[i].getHeight());
        }
    }

    @Override
    public void start(Stage primaryStage) {
        groupS = new Group();
        mainS = new Scene(groupS, WIDTH, HEIGHT, Color.DARKBLUE);
        window = primaryStage;
        window.setScene(mainS);
        window.setTitle(TITLE);
        window.show();

        Media audioMedia = new Media(AUDIO_URI);
        audioMP = new MediaPlayer(audioMedia);
        audioMP.play();
        audioMP.setCycleCount(MediaPlayer.INDEFINITE);
        audioMP.setVolume(0.02);
        audioMP.setAudioSpectrumInterval(0.01);
        audioMP.setAudioSpectrumNumBands(8);
        audioMP.setAudioSpectrumListener(this);

        rect[0] = new Rectangle(250, HEIGHT / 2 - 50, 50, 50);
        rect[0].setFill(Color.AZURE);
        rect[1] = new Rectangle(350, HEIGHT / 2 - 50, 50, 50);
        rect[1].setFill(Color.CORNFLOWERBLUE);
        rect[2] ...

This is what I right now have:
Right now I am facing how to make these rectangles make more reactive like they change about 60 pixels maximal higher and I want to make it more than 60 pixels. Now I don't have a question this is just an update for my code.

package com.VINSTORM.bleidorb.AudioWaveFormFX_V1.v_aa;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.AudioSpectrumListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class AWF_FX_v1 extends Application implements AudioSpectrumListener {

    public final static String TITLE = "AWF special program";
    public final static short WIDTH = 1280;
    public final static short HEIGHT = 720;
    public static String AUDIO_FILE = "../mp3Music/Cynematic - Waterbased.mp3";
    public static String AUDIO_FILE1 = "../mp3Music/AcerDroid -Skies.mp3";
    public static String AUDIO_FILE2 = "../mp3Music/Capturez - Patterns.mp3";
    public static String AUDIO_FILE3 = "../mp3Music/Kanooli - Instinct.mp3";
    public static String AUDIO_FILE4 = "../mp3Music/RavenKreyn_InTheAir_NCSrelease.mp3";
    public static String AUDIO_URI = AWF_FX_v1.class.getResource(AUDIO_FILE2).toExternalForm();

    private Stage window;
    private Scene mainS;
    private Group groupS;
    private MediaPlayer audioMP;
    private float[] cMag;

//  private Rectangle rect0;
//  private Rectangle rect1;
//  private Rectangle rect2;
//  private Rectangle rect3;
//  private Rectangle rect4;
//  private Rectangle rect5;
//  private Rectangle rect6;
//  private Rectangle rect7;

    private Rectangle[] rect = new Rectangle[8];

    @Override
    public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) {
        for (int i = 0; i < magnitudes.length; i++) {
            cMag = magnitudes;
            cMag[i] = (int) cMag[i];
            //System.out.println((i + 1) + ": " + (cMag[i] * -1));
        }
        for(int i = 0; i < rect.length; i++) {
            rect[i].setY(310 + ...

filesandprojectsIguess.PNG

that v7 -> v1 is not accidental. I just made a new package in v7.
if I placed the class just in v7, the error is gone and the music can play, but if the class is inside of v7.v1 then I get that error.

I got a error from this: "public static String AUDIO_URI = AWF_Core.class.getResource(AUDIO_FILE).toExternalForm();"
I made a new class, so the code looks more cleaner and readable.
but unfortunatly I don't know what happened?

I got a error:

Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$2(LauncherImpl.java:352)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at com.VINSTORM.bleidorb.AudioWaveFormFX_V1.v7.v1.AWF_Core.<clinit>(AWF_Core.java:18)
    ... 11 more
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:383)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    ... 5 more

this is how my project folders looks like in the navigator.

filesandprojectsIguess.PNG

here is my new code:

package com.VINSTORM.bleidorb.AudioWaveFormFX_V1.v7.v1;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.AudioSpectrumListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class AWF_Core extends Application implements AudioSpectrumListener {

    public final static String TITLE = "AWF special program";
    public final static short WIDTH = 1280;
    public final static short HEIGHT = 720;
    public static String AUDIO_FILE = "../mp3Music/Cynematic - Waterbased.mp3";
    public static String AUDIO_URI = AWF_Core.class.getResource(AUDIO_FILE).toExternalForm();

    private Stage window;
    private Scene mainS;
    private Group groupS;
    private static MediaPlayer audioMP;

    @Override
    public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) {
        System.out.println("data updated");
        displayMag(magnitudes);
    }

    public void displayMag(float[] mag) {
        for(int i = 0; i < mag.length; i++) {
            System.out.println(i+": " + mag[i]);
        }
        System.out.println("length of mag = " + mag.length);
    }

    public void init() {
        Media audioMedia ...

this is what the console says:

data updated
0: -59.407444
1: -48.37642
2: -41.535774
3: -40.149982
4: -44.27457
5: -44.982887
6: -48.725376
7: -52.21941
8: -54.77891
9: -50.22617
10: -53.42569
11: -55.172703
12: -55.079517
13: -53.60956
14: -53.745964
15: -57.46172
16: -57.445312
17: -57.044395
18: -52.888622
19: -54.909782
20: -57.15198
21: -56.71712
22: -56.429665
23: -57.09065
24: -57.157146
25: -57.19809
26: -57.740284
27: -56.86342
28: -56.226715
29: -57.350414
30: -57.268696
31: -57.377327
32: -57.740887
33: -56.40759
34: -55.88547
35: -56.44446
36: -57.326187
37: -57.204216
38: -55.604618
39: -55.611687
40: -56.671505
41: -55.99083
42: -54.81242
43: -54.81779
44: -55.155308
45: -54.862213
46: -56.785095
47: -57.21616
48: -56.16005
49: -56.611744
50: -57.336994
51: -56.80366
52: -56.719086
53: -56.731297
54: -57.696148
55: -56.97476
56: -57.19966
57: -56.635822
58: -56.079693
59: -56.365444
60: -56.58281
61: -57.3104
62: -57.90639
63: -57.26793
64: -57.42998
65: -58.106003
66: -56.51674
67: -55.527695
68: -55.31978
69: -56.59834
70: -57.75076
71: -57.570744
72: -55.88267
73: -55.103874
74: -56.05077
75: -56.008892
76: -55.499
77: -56.47118
78: -56.83968
79: -57.00147
80: -56.647213
81: -56.488712
82: -55.836987
83: -56.97192
84: -57.72063
85: -58.830986
86: -58.433346
87: -57.937386
88: -58.045086
89: -57.081215
90: -56.94066
91: -57.460472
92: -57.537506
93: -57.83281
94: -58.671604
95: -58.726414
96: -58.39954
97: -57.964382
98: -59.422413
99: -58.608257
100: -56.711
101: -57.214962
102: -58.341293
103: -58.0045
104: -58.1659
105: -57.890232
106: -57.620907
107: -58.689537
108: -58.754578
109: -58.455357
110: -58.3346
111: -57.839603
112: -58.051525
113: -58.993805
114: -59.581917
115: -59.176373
116: -58.17461
117: -59.15124
118: -59.001194
119: -58.830784
120: -58.5519 ...

yes! Now I can finally use the values :D

this is my code:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.AudioSpectrumListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class AWF_Main extends Application implements AudioSpectrumListener {

    public final static String TITLE = "AWF special program";
    public final static short WIDTH = 1280;
    public final static short HEIGHT = 720;
    public static String AUDIO_FILE = "../mp3Music/Cynematic - Waterbased.mp3";
    public static String AUDIO_URI = AWF_Main.class.getResource(AUDIO_FILE).toExternalForm();

    private Stage window;
    private Scene mainS;
    private Group groupS;
    private static MediaPlayer audioMP;

    @Override
    public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) {
        System.out.println("data updated");
        displayMag(magnitudes);
        for(int i = 0; i < magnitudes.length; i++) {
            //correctedMagnitude[i] = magnitudes[i] - audioMP.getAudioSpectrumThreshold();
//            System.out.println("0"+magnitudes[0]);
//            System.out.println("1"+magnitudes[1]);
//            System.out.println("2"+magnitudes[2]);
//            System.out.println("3"+magnitudes[3]);
//            System.out.println("4"+magnitudes[4]);
//            System.out.println("5"+magnitudes[5]);
//            System.out.println("6"+magnitudes[6]);
//            System.out.println("7"+magnitudes[7]);
//            System.out.println("8"+magnitudes[8]);
//            System.out.println("9"+magnitudes[9]);
            //System.out.println(correctedMagnitude[i]);
        }
    }

    public void displayMag(float[] mag) {
        for(int i = 0; i < mag.length; i++) {
            System.out.println(i+": " + mag[i]);
        }
        System.out.println("length of mag = " + mag.length);
    }

    public void init() {
        Media audioMedia = new Media(AUDIO_URI);
        audioMP = new MediaPlayer(audioMedia);
        play();
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        groupS = new Group();
        mainS = new Scene(groupS, WIDTH/2, HEIGHT/2, Color.DEEPPINK);
        window = primaryStage;
        window.setScene(mainS);
        window.setTitle(TITLE);
        window.show();
    }

    //audioMP.setVolume(0.02); is low, because I just like to listen in low volume while I listen to other music. (:
    public void play() {
        audioMP.play();
        audioMP.setVolume(0.02);
        audioMP.setAudioSpectrumInterval(0.5);
        audioMP.setAudioSpectrumNumBands(256);
        audioMP.setAudioSpectrumListener(this);
        //AWF_newClass.printOutMagnitudes();
    }

    public void stop() {
        System.out.println("program exited");
    }

    public static void main(String[] args) { ...
at com.VINSTORM.bleidorb.AudioWaveFormFX_V1.v1.AWF_Main.start(AWF_Main.java:52) = System.out.println(correctedMagnitude[5]);

btw, this is a link too:
jnlps://download.oracle.com/otndocs/products/javafx/8/samples/Ensemble/Ensemble.jnlp
there is a audiobarchart.

I just want to System.out.println(magnitudes[i]);
in the start method, but how do I even do that?
I tried this:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.AudioSpectrumListener;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class AWF_Main extends Application implements AudioSpectrumListener {

    public final static String TITLE = "AWF special program";
    public final static short WIDTH = 1280;
    public final static short HEIGHT = 720;
    public static String AUDIO_FILE = "../mp3Music/Cynematic - Waterbased.mp3";
    public static String AUDIO_URI = AWF_Main.class.getResource(AUDIO_FILE).toExternalForm();

    private Stage window;
    private Scene mainS;
    private Group groupS;
    private AudioSpectrumListener asl;
    private static MediaPlayer audioMP;
    private float[] correctedMagnitude;

    @Override
    public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) {
        for(int i = 0; i < magnitudes.length; i++) {
            correctedMagnitude[i] = magnitudes[i] - audioMP.getAudioSpectrumThreshold();
            //System.out.println(correctedMagnitude[i]);
        }
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        groupS = new Group();
        mainS = new Scene(groupS, WIDTH, HEIGHT, Color.DEEPPINK);
        window = primaryStage;
        window.setScene(mainS);
        window.setTitle(TITLE);
        window.show();

        // setup media
        Media audioMedia = new Media(AUDIO_URI);
        audioMP = new MediaPlayer(audioMedia);
        audioMP.setAudioSpectrumListener(this);
        play();

        //correctedMagnitude[5], why 5, because I chosed a random number.
        System.out.println(correctedMagnitude[5]);
    }

    //audioMP.setVolume(0.02); is low, because I just like to listen in low volume while I listen to other music. (:
    public void play() {
        audioMP.play();
        audioMP.setVolume(0.02);
        audioMP.setAudioSpectrumInterval(60.0);
        audioMP.setAudioSpectrumNumBands(256);
    }

    public void stop() {
        System.out.println("program exited");
    }

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

I don't want to use charts.

here is my Error:

Exception in Application start method
program exited
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at ...

I just need the magnitudes to be accesable from the whole class.
(btw, I am going to remove animationtimer

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.

I was kinda stuck, but I finally got it. I just forgot that the thread starts first then the initialize.
it is now fixed. Here is the complete code:

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 implements Runnable {

    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;

    public void init() {

    }

    @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);
                    ta.appendText(server + "\n");
                    // ta.appendText(dis.readUTF() + "\n");
                    dos.flush();
                } 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);

            try {
                new Thread(this).start();
                } catch (Exception e) {
                    e.printStackTrace();
                }

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

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

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

    @Override
    public void run() {
        try {
            ss = new ServerSocket(5279, 100);
            s = ss.accept();
            s.setTcpNoDelay(true);
            dis = new DataInputStream(s.getInputStream());
            dos = ...

do you have a link of that book?
btw, if you know some database tutorials or guides then give me the link if you want (:

when I type something in the server and press enter in the textfield, it displayed in the server program, but not in the client program.

when I type something in the client and press enter in the textfield, it displayed in the server and client program, this one works fine.

server -> client (message not displayed on client, message displayed only on server)
client -> server (message displayed on both programs)

so I run the Server Program then the Client Program and when I type something in the server textfield and press enter, I get a error inside the Client Class.

client test input
java.lang.NullPointerException
    at com.VINSTORM.bleidorb.ZcommunicationTestServerV4.main.Client.run(Client.java:104)
    at java.lang.Thread.run(Unknown Source)

Client.java:104 =

                ta.appendText(dis.readUTF() + "\n");

So I am really interested in making a database, I have knowledge about html and css, not javascript and I just want to begin learning and making a database.
I am going to use this website: https://www.000webhost.com/?utm_source=000webhostapp&utm_campaign=000_logo&utm_medium=website&utm_content=footer_img
so you can see my website in the internet, I don't really expect a lot of people are going to my website, like more than 20 people in a day, but here is the question or discussion?
how and where do I begin learn about databases, I don't really care what language I am going to use, like sql or php, is sql even a language? I don't know.
I just need a ton of information (:

btw, do I need to host a sql server or something, I am not going to pay anything with money.
I already downloaded xampp, I don't know if this going to help me.

much better code here
I just don't see the server message in the client program

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 implements Runnable {

    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;

    public void init() {
        new Thread(this).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);
                    ta.appendText(server + "\n");
                    // ta.appendText(dis.readUTF() + "\n");
                    dos.flush();
                } 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 {
            new Thread(this).stop();
            dis.close();
            ss.close();
            s.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

    @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());

            for (;;) {
                System.out.println("server test input");
                ta.appendText(dis.readUTF() + "\n");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

import java.io.DataInputStream; ...

ignore the code above please, I forgot that I can use one class instead of two, just for the "implements runnable".
let me simplify this code.

the client does not get the server message, what went wrong?
btw I used the "implements Runnable" (:
I don't know how to fully use lambdas, I read this: https://www.freecodecamp.org/news/learn-these-4-things-and-working-with-lambda-expressions-b0ab36e0fffc/
rn, I am not really focusing on lambdas, it's nice to know, I will make a seperate project to test it out, but there is something wrong with the client input, (that gets the server messages from the server) ,or the server output, (that sends the server messages to the client). I don't know if for loop is making some problems, I just have a feeling of it, but I don't know why?

btw here is my code:

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() {
        new Thread(new ConnectionThread()).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);
                    ta.appendText(server + "\n");
                    // ta.appendText(dis.readUTF() + "\n");
                    dos.flush();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                tf.clear();
            });

            ta ...

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 ...

I somehow got this, I made a new class and I extended to Thread,
I did then this, I don't know what this is called:
but like so, "ServerInnerClass sic = new ServerInnerClass();"
then I started the thread, by doing this. sic.start();
in the ServerInnerClass, I made the run method.
And I placed the socket.accept in there.
Does this stop from lagging? freezing? IDK what it is called, but this fixed it.
of course, I know a little bit of threading (:
and I need to learn more about it.

I will finish my server-client program thing. And I might post a minimalistic example
of this answer.

source link that helped me: http://tutorials.jenkov.com/java-concurrency/creating-and-starting-threads.html

rproffitt commented: After all this, I worry you are not getting it. If you have a blocking call, it appears to freeze, but is NOT frozen. +15
//I forgot to put this in my code:
//"server = new ServerSocket(6789, 100);"

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.application.Platform;
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 ServerChatProgram extends Application{

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

    private Stage window;
    private Scene scene;
    private Group root;
    private TextField inputMessages;
    private TextArea viewsMessages;

    private void startRunning() {
        try {
            server = new ServerSocket(6789, 100);
            new AnimationTimer() {

                @Override
                public void handle(long now) {
                    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();
        }
    }
    private void waitForConnection() throws IOException{

            showMessage(" Waiting for someone to connect... \n");
            System.out.println("hello");
        try {
            connection = server.accept();
        }catch (IOException e) {
            e.printStackTrace();
        }
            showMessage(" Now connected to " + connection.getInetAddress().getHostName());
            System.out.println(connection.getInetAddress().getHostName().toString());
    }

    private void setupStreams() throws IOException{}
    private void whileChatting() throws IOException{}
    private void closeCrap(){}
    private void sendMessage(String message){}
    private void showMessage(final String text){
        Platform.runLater(() -> {
            viewsMessages.appendText(text);
        });
    }
    private void ableToType(final boolean tof){}

    private void createContent() {

        inputMessages = new TextField();
        inputMessages.setTranslateX(10);
        inputMessages.setTranslateY(10);
        inputMessages.setPrefWidth(340);
        inputMessages.setPrefHeight(20);

        viewsMessages = new TextArea();
        viewsMessages.setTranslateX(10);
        viewsMessages.setTranslateY(50);
        viewsMessages.setPrefWidth(340);
        viewsMessages.setPrefHeight(300);

        inputMessages.setOnAction(event -> {
            String Message = "Server: ";
            Message += inputMessages.getText();
            inputMessages.clear();
            viewsMessages.appendText(Message + "\n");
        });

        root = new Group(inputMessages, viewsMessages);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        createContent();
        scene = new Scene(root, 640, 360, Color.LIGHTCYAN);
        window = primaryStage; ...

https://stackoverflow.com/questions/9872356/java-socket-accept-freezes-ui

I got the:
new Runnable(){@Override public void run() {}}; idea from that site.

//I did this, but I saw nothing in the console, the waitForConnection() method does nothing ):

private void startRunning() {
        try{
            waitForConnection();
            setupStreams();
            whileChatting();
         }catch(EOFException eofException){
            showMessage("\n Server ended the connection! ");
         }catch (IOException IOException){
            IOException.printStackTrace();
         }finally{
            closeCrap();
         }
    }
    private void waitForConnection() throws IOException{
        new Runnable(){
            @Override
            public void run() {
                showMessage(" Waiting for someone to connect... \n");
                System.out.println("hello");
                try {
                    connection = server.accept();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                showMessage(" Now connected to " + connection.getInetAddress().getHostName());
                System.out.println(connection.getInetAddress().getHostName().toString());
        }};
    }