Facebook
From Sexy Anoa, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 266
  1. import javafx.scene.paint.Color;
  2. import javafx.application.Application;
  3. import javafx.event.ActionEvent;
  4. import javafx.event.EventHandler;
  5. import javafx.geometry.Insets;
  6. import javafx.geometry.Pos;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.control.Menu;
  10. import javafx.scene.control.MenuBar;
  11. import javafx.scene.control.TextArea;
  12. import javafx.scene.control.TextField;
  13. import javafx.scene.layout.GridPane;
  14. import javafx.scene.layout.HBox;
  15. import javafx.scene.layout.Priority;
  16. import javafx.scene.layout.VBox;
  17. import javafx.stage.Stage;
  18.  
  19. public class ApplicationMain extends Application {
  20.        
  21.         Stage window;
  22.        
  23.         // Main Method
  24.         public static void main(String[] args) {
  25.                
  26.                 launch(args);
  27.                
  28.         }
  29.        
  30.         // Scene Method
  31.         @SuppressWarnings("static-access")
  32.         @Override
  33.         public void start(Stage primaryStage) {
  34.                
  35.                 // Window Stuff
  36.                 window = primaryStage;
  37.                 window.setTitle("Chat Application");
  38.                
  39.                 // Setup Grid Layout
  40.                 GridPane grid = new GridPane();
  41.                 grid.setAlignment(Pos.TOP_LEFT);
  42.                 grid.setHgap(10);
  43.                 grid.setStyle("-fx-background-color: #272828;");
  44.                
  45.                 // MenuBar
  46.                 MenuBar menu = new MenuBar();
  47.                
  48.                 menu.setPrefWidth(1000);
  49.                 menu.setPrefHeight(20);
  50.                
  51.                 // Creation of File + Help
  52.                 Menu file = new Menu("File");
  53.                 Menu help = new Menu("Help");
  54.                
  55.                 // Add the Menus to the MenuBar
  56.                 menu.getMenus().add(file);
  57.                 menu.getMenus().add(help);
  58.                                
  59.                 // Add MenuBar to Scene
  60.                 menu.setVisible(true);
  61.                 grid.add(menu, 0, 0);
  62.                
  63.                 // Text Area Stuff
  64.                 TextArea area = new TextArea();
  65.  
  66.                 area.setPrefWidth(1000);
  67.                 area.setPrefHeight(700);
  68.                 area.setEditable(false);
  69.                 area.setStyle("-fx-control-inner-background: #313233;");
  70.  
  71.                 // Add Text Area to Grid
  72.                 grid.add(area, 0, 1);
  73.                
  74.                 // Text Field
  75.                 TextField enter = new TextField();
  76.                
  77.                 enter.setPromptText("Type here...");
  78.                 enter.setMaxWidth(920);
  79.                 enter.setMaxHeight(30);
  80.                 enter.setStyle("-fx-padding: 5px;");
  81.                
  82.                 // Button
  83.                 Button send = new Button("Send!");
  84.                
  85.                 // Set the Handler for the Send Button Event
  86.                 send.setOnAction(new EventHandler<ActionEvent>() {
  87.                         @Override
  88.                         public void handle(ActionEvent event) {
  89.                                
  90.                                 // Area Text Content
  91.                                 area.setText(area.getText() + Color.BLUE + "Kathleen: " + Color.WHITE + enter.getText() + "\n");
  92.                                 enter.setText("");
  93.                        
  94.                         }
  95.                        
  96.                 });
  97.                
  98.                 // Use of HBox to Space out Text Field & Send Button
  99.                 HBox row = new HBox();
  100.                
  101.                 row.setSpacing(10);
  102.                 row.setHgrow(enter, Priority.ALWAYS);
  103.                 row.getChildren().addAll(enter, send);
  104.                
  105.                 // Use of VBox to Space out Text Field
  106.                 VBox box = new VBox();
  107.                 box.setSpacing(10);
  108.                 box.setPadding(new Insets(10));
  109.                 box.getChildren().add(row);
  110.                
  111.                 // Add HBox in VBox to Grid
  112.                 grid.add(box, 0, 2);
  113.                
  114.                 // Scene Stuff
  115.                 Scene scene = new Scene(grid, 1000, 750);
  116.                 window.setScene(scene);
  117.                
  118.                 // Display the Window
  119.                 window.show();
  120.                
  121.         }      
  122.        
  123. }
  124.