Skip to content

Instantly share code, notes, and snippets.

@Clumsy-Coder
Created November 7, 2016 20:12
Show Gist options
  • Save Clumsy-Coder/bc00ec884a7e8e1cd394d1f4964d1d30 to your computer and use it in GitHub Desktop.
Save Clumsy-Coder/bc00ec884a7e8e1cd394d1f4964d1d30 to your computer and use it in GitHub Desktop.
The controller class (ClientChatController.java) fxml being used (clientGUI.fxml) and the JFXDialog that needs to be used (dialog.fxml)
package client.gui;
import com.jfoenix.controls.*;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
/**
* @author Umar
* Class used to respond to events from clientGUI.fxml
*/
public class ClientChatController implements Initializable
{
private ArrayList<Label> users = new ArrayList<Label>();
@FXML
private JFXListView<Label> userList;
@FXML
private JFXListView<Label> conversationList;
@FXML
private StackPane stackPane;
@FXML
private JFXTextField username;
@FXML
private JFXTextField firstname;
@FXML
private JFXTextField lastname;
@FXML
private JFXTextField serverIP;
@Override
public void initialize(URL location, ResourceBundle resources)
{
//open dialog that contains text field for username, firstname,
//lastname and server IP address
JFXDialogLayout content = new JFXDialogLayout();
content.setHeading(new Text("Setup"));
VBox vbox = new VBox(10);
vbox.getChildren()
.addAll(username, firstname, lastname, serverIP);
content.setBody(vbox);
JFXDialog dialog = new JFXDialog(stackPane, content, JFXDialog.DialogTransition.CENTER);
JFXButton button = new JFXButton("Connect");
button.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
System.out.println("Username: " + username.getText());
System.out.println("Firstname: " + firstname.getText());
System.out.println("Lastname: " + lastname.getText());
System.out.println("ServerIP: " + serverIP.getText());
dialog.close();
}
});
content.setActions(button);
dialog.show();
}
@FXML
public void clientSetup(ActionEvent event)
{
System.out.println("Username: " + username);
System.out.println("Firstname: " + firstname);
System.out.println("Lastname: " + lastname);
System.out.println("ServerIP: " + serverIP);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
<StackPane fx:id="stackPane"
xmlns="http://javafx.com/javafx/8.0.112-ea"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="client.gui.ClientChatController">
<BorderPane
>
<left>
<ScrollPane fitToHeight="true"
fitToWidth="true">
<content>
<JFXListView fx:id="userList"/>
</content>
</ScrollPane>
</left>
<right>
<BorderPane>
<center>
<ScrollPane fitToWidth="true">
<content>
<JFXListView fx:id="conversationList"/>
</content>
</ScrollPane>
</center>
<bottom>
<BorderPane>
<padding>
<Insets bottom="5"
top="1"/>
</padding>
<center>
<JFXTextArea fx:id="textArea"
maxHeight="92"
maxWidth="450"
promptText="Type message"
disable="true">
</JFXTextArea>
</center>
<right>
<JFXButton fx:id="sendBtn"
alignment="CENTER"
buttonType="FLAT"
disable="true"
maxHeight="1.7976931348623157E308"
maxWidth="110.0"
ripplerFill="#4059a9"
text="Send"
textAlignment="CENTER">
</JFXButton>
</right>
</BorderPane>
</bottom>
</BorderPane>
</right>
</BorderPane>
<JFXDialog fx:id="setupDialog">
<JFXDialogLayout>
<heading>
<Label>Setup</Label>
</heading>
<body>
<VBox spacing="10">
<JFXTextField fx:id="username"
promptText="Username"
>Username
</JFXTextField>
<JFXTextField fx:id="firstname"
promptText="First name"
>Firstname
</JFXTextField>
<JFXTextField fx:id="lastname"
promptText="Last name"
>Lastname
</JFXTextField>
<JFXTextField fx:id="serverIP"
promptText="Server IP address"
>Server IP Address
</JFXTextField>
</VBox>
</body>
<actions>
<HBox>
<Text fx:id="errorMessage"></Text>
<JFXButton fx:id="connectBtn" onAction="#clientSetup">Connect</JFXButton>
</HBox>
</actions>
</JFXDialogLayout>
</JFXDialog>
</StackPane>
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<StackPane
xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/2.2"
fx:controller="client.gui.ClientChatController">
<JFXDialog fx:id="setupDialog">
<JFXDialogLayout>
<heading>
<Label>Setup</Label>
</heading>
<body>
<VBox spacing="10">
<JFXTextField fx:id="username"
promptText="Username"
maxWidth="20">
</JFXTextField>
<JFXTextField fx:id="firstName"
promptText="First name"
maxWidth="20">
</JFXTextField>
<JFXTextField fx:id="lastname"
promptText="Last name"
maxWidth="20">
</JFXTextField>
<JFXTextField fx:id="serverIP"
promptText="Server IP address"
maxWidth="20">
</JFXTextField>
</VBox>
</body>
<actions>
<JFXButton fx:id="connectBtn">Connect</JFXButton>
</actions>
</JFXDialogLayout>
</JFXDialog>
</StackPane>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment