- import javafx.scene.paint.Color;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Menu;
- import javafx.scene.control.MenuBar;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.Priority;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- public class ApplicationMain extends Application {
- Stage window;
- // Main Method
- public static void main(String[] args) {
- launch(args);
- }
- // Scene Method
- @SuppressWarnings("static-access")
- @Override
- public void start(Stage primaryStage) {
- // Window Stuff
- window = primaryStage;
- window.setTitle("Chat Application");
- // Setup Grid Layout
- GridPane grid = new GridPane();
- grid.setAlignment(Pos.TOP_LEFT);
- grid.setHgap(10);
- grid.setStyle("-fx-background-color: #272828;");
- // MenuBar
- MenuBar menu = new MenuBar();
- menu.setPrefWidth(1000);
- menu.setPrefHeight(20);
- // Creation of File + Help
- Menu file = new Menu("File");
- Menu help = new Menu("Help");
- // Add the Menus to the MenuBar
- menu.getMenus().add(file);
- menu.getMenus().add(help);
- // Add MenuBar to Scene
- menu.setVisible(true);
- grid.add(menu, 0, 0);
- // Text Area Stuff
- TextArea area = new TextArea();
- area.setPrefWidth(1000);
- area.setPrefHeight(700);
- area.setEditable(false);
- area.setStyle("-fx-control-inner-background: #313233;");
- // Add Text Area to Grid
- grid.add(area, 0, 1);
- // Text Field
- TextField enter = new TextField();
- enter.setPromptText("Type here...");
- enter.setMaxWidth(920);
- enter.setMaxHeight(30);
- enter.setStyle("-fx-padding: 5px;");
- // Button
- Button send = new Button("Send!");
- // Set the Handler for the Send Button Event
- send.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- // Area Text Content
- area.setText(area.getText() + Color.BLUE + "Kathleen: " + Color.WHITE + enter.getText() + "\n");
- enter.setText("");
- }
- });
- // Use of HBox to Space out Text Field & Send Button
- HBox row = new HBox();
- row.setSpacing(10);
- row.setHgrow(enter, Priority.ALWAYS);
- row.getChildren().addAll(enter, send);
- // Use of VBox to Space out Text Field
- VBox box = new VBox();
- box.setSpacing(10);
- box.setPadding(new Insets(10));
- box.getChildren().add(row);
- // Add HBox in VBox to Grid
- grid.add(box, 0, 2);
- // Scene Stuff
- Scene scene = new Scene(grid, 1000, 750);
- window.setScene(scene);
- // Display the Window
- window.show();
- }
- }