Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. public class LogController{
  2. @FXML private TextArea logTextAreaFx;
  3. public void handlelogTextAreaFX(ActionEvent event, String text){
  4. logTextAreaFx.appendText(text);
  5. }
  6.  
  7. public class MainController{
  8. @FXML LogController logController;
  9. public void handleChatConsoleButton(ActionEvent event){
  10. logController.handlelogTextAreaFX(event, "test");
  11. }
  12.  
  13. <VBox prefWidth="500" prefHeight="300" id="logView" fx:controller="LogController" xmlns:fx="http://javafx.com/fxml" >
  14. <TextArea text="-------- Log ---------" id="logTextArea" fx:id="logTextAreaFx"></TextArea>
  15.  
  16. <VBox minHeight="520" minWidth="1280" fx:controller="MainController" xmlns:fx="http://javafx.com/fxml">
  17. <Button text="test Button" onAction="#handleChatConsoleButton"></Button>
  18.  
  19. public class ClientController {
  20. private ClientView clientView;
  21. @FXML private MainController mainController;
  22. @FXML private LogController logController;
  23. public ClientController(){
  24. this.clientView = new ClientView();
  25. }
  26. public void showView(){
  27. this.clientView.startView();
  28. }
  29. public void setText(String text){
  30. logController.handlelogTextAreaFX(null, "hello world");
  31. }
  32.  
  33. public class GameMain {
  34. static ClientController controller;
  35. public static void main(String[] args){
  36. controller = new ClientController();
  37. controller.showView();
  38. }
  39.  
  40. public class ClientView extends Application{
  41. VBox root = new VBox();
  42. VBox mainStage;
  43. public void startView(){
  44. launch();
  45. }
  46. @Override
  47. public void start(Stage primaryStage) throws Exception {
  48. Scene scene = new Scene(root);
  49. loadMainStage();
  50. loadLogStage();
  51. primaryStage.setScene(scene);
  52. primaryStage.show();
  53. }
  54.  
  55.  
  56. @FXML Pane MainStage;
  57. public void loadMainStage(){
  58. mainStage = new VBox();
  59. try {
  60. mainStage = FXMLLoader.load(getClass().getClassLoader().getResource("MainStage.fxml"));
  61. } catch (IOException e) {
  62. e.printStackTrace();
  63. }
  64. root.getChildren().add(mainStage);
  65. }
  66. @FXML VBox LogStage;
  67. public void loadLogStage(){
  68. //ClientController controller = new ClientController();
  69. FXMLLoader loader = new FXMLLoader();
  70. Pane root = new Pane();
  71. Scene chatScene = new Scene(root);
  72. Stage stage = new Stage();
  73. stage.setTitle("Log View");
  74. stage.setScene(chatScene);
  75. stage.setResizable(true);
  76. try {
  77. //loader.setController(controller);
  78. LogStage = loader.load(getClass().getClassLoader().getResource("LogStage.fxml"));
  79. } catch (IOException e) {
  80. e.printStackTrace();
  81. }
  82. root.getChildren().add(LogStage);
  83. stage.show();
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement