#Help creating a separate window for each client

1 messages · Page 1 of 1 (latest)

robust obsidianBOT
#

<@&987246487241105418> please have a look, thanks.

robust obsidianBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

candid jewel
#

So you just need to figure out how to create a JavaFX program from the looks of it and add a button action that calls the sendMessageToServer function right?

#
<dependency>
  <groupId>org.openjfx</groupId>
  <artifactId>javafx-controls</artifactId>
  <version>${javafx.version}</version>
</dependency>
<dependency>
  <groupId>org.openjfx</groupId>
  <artifactId>javafx-fxml</artifactId>
  <version>${javafx.version}</version>
</dependency>
...
<plugin>
  <groupId>org.openjfx</groupId>
  <artifactId>javafx-maven-plugin</artifactId>
  <version>${javafx-maven-plugin.version}</version>
  <configuration>
    <mainClass>example.Main</mainClass>
  </configuration>
</plugin>
``` You can add this to your maven pom.xml (for example) to get started with JavaFX
#

and this sample Main.java ```java
package example;

import javafx.application.Application;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage stage) throws Exception {
    stage.show();
}

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

}

#

then if you run the javafx:run action in Maven you should see an empty JavaFX gui

#

from here you can create your GUI and add all the elements you need

#

e.g. TextArea for the chat area, TextField for the input area and Button for the send button

#

are you running multiple Client's in the same instance?

#

so 1 main method should open more than 1 gui?

#

so run your application multiple times?

#

lol

#
public class Main extends Application {
    private Socket socket;
    
    @Override
    public void start(Stage stage) throws Exception {
        TextArea textArea = new TextArea();
        TextField textField = new TextField();

        Button button = new Button("Send");
        button.addActionListener(event -> {
            String text = textField.getText();
            try {
                socket.getOutputStream().write(text.getBytes());
                socket.getOutputStream().flush();
            } catch (IOException ex) {
                // Handle the send error
            }
        });

        stage.show();
    }

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

so something like this

#

Socket is whatever your networking call should be

#

doesn't sound like it is

#

maybe the issue is in your module-info.java, if you post that I can check

#

Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class com.roborallypackage.view.TestApplication (in module com.roborallypackage) because module com.roborallypackage does not export com.roborallypackage.view to module javafx.graphics

#

I gues you need

#

opens com.roborallypackage.view to javafx.fxml;

#

I hate module-info.java so much

#

ah yeah you do

#

I'm not sure, I've avoided module-info like the plague, so can't help there

#

are you just using the module system for Javafx? you might find it easier just to use the maven plugin

#

otherwise, hopefully somebody with more knowledge than me can help you

#

maybe take a step back and look into the tech you're using?

verbal roost
#

The error says you're not exporting to javafx.graphics

candid jewel
#

it's easier to break everything down, research into what you don't understand and then continue what you're doing once you know why and how something is needed/used

verbal roost
#

Same way you're exporting to javafx.fxml java exports com.roborallypackage.view to javafx.graphics

#

Use a comma to separate your exports

#

The path you're using for your FXML file isn't proper

#

It can't find your FXML using the path you gave it

#

What path are you using, and where is the file located?

#

A path is a written string specifying where a file is

#

You already put it in your code, you passed the path to the FXMLLoader

#

Show the path you specified, and the exact location of the file

#

"On my PC" doesn't help us

#

Yes

#

An example of a Windows path would be C:/Users/Your Name/Desktop/your file.txt

#

If you're going to be a software developer, yes, you'll have to get used to reading technical articles

#

You have to make the path you're passing to the FXMLLoader match where the file is

#

Post the path you're using

#

It's not 4 hour articles for minor things. There are other articles that explain it in simpler terms

#

You need to do research

#

Yes, that is where you are specifying the path

#

Where is testView.fxml within your project?

#

Is TestApplication the class trying to load the file?

#

getResource is going to load from your resources folder, using the same package name as the class

#

What do you think you should do, based on what I said?

#

You gotta put a bit of thought into it

#

You can move the file to a new folder, called view

#

Is the class in package view or com.roborallypackage.view?

robust obsidianBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍

frigid lance
#

Hello did you get help with this?