Advertisement
Guest User

crowdnna game paste

a guest
Apr 5th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | Software | 0 0
  1.  
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5.  
  6. import javafx.application.Application;
  7. import javafx.event.ActionEvent;
  8. import javafx.event.EventHandler;
  9. import javafx.scene.Group;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.Label;
  13. import javafx.scene.control.TextField;
  14. import javafx.scene.layout.HBox;
  15. import javafx.scene.layout.VBox;
  16. import javafx.scene.text.Font;
  17. import javafx.stage.Stage;
  18.  
  19. public class opening extends Application {
  20.  
  21. @Override
  22. public void start(Stage primaryStage) throws Exception {
  23. // needs buttons to select what to do and also a text field to store a name
  24.  
  25. Label gameTitle = new Label("Basil's Cat Game :3");
  26. gameTitle.setFont(Font.font(STYLESHEET_CASPIAN, 50));
  27. Label putNameTxt = new Label("Name:");
  28. putNameTxt.setFont(Font.font(STYLESHEET_CASPIAN, 30));
  29.  
  30. TextField putNameHere = new TextField();
  31. putNameHere.setMaxSize(500, 500);
  32.  
  33. Button nameOkButton = new Button("OK");
  34. nameOkButton.setMaxSize(20, 10);
  35.  
  36. nameOkButton.setOnAction(new EventHandler<ActionEvent>() {
  37.  
  38. @Override
  39. public void handle(ActionEvent saveName) {
  40. String nameText = putNameHere.getText();
  41. File nameFile = new File("NameFile.txt");
  42. try {
  43. FileWriter fw = new FileWriter(nameFile);
  44. fw.write(nameText);
  45. fw.close();
  46.  
  47. } catch (IOException e) {
  48. Group titleGroup = new Group();
  49. Label errLbl = new Label("Hello World!");
  50. titleGroup.getChildren().add(errLbl);
  51.  
  52. Scene scene = new Scene(titleGroup, 500, 500);
  53. primaryStage.setTitle("try again <3");
  54. primaryStage.setScene(scene);
  55. primaryStage.show();
  56. e.printStackTrace();
  57. }
  58.  
  59. VBox titleVBox = new VBox();
  60. titleVBox.getChildren().add(gameTitle);
  61. titleVBox.getChildren().add(putNameTxt);
  62. titleVBox.setMaxSize(250, 250);
  63.  
  64. HBox titleHBox = new HBox();
  65. titleHBox.getChildren().add(putNameHere);
  66. titleHBox.getChildren().add(nameOkButton);
  67. titleHBox.setMaxSize(250, 250);
  68.  
  69. Group titleGroup = new Group();
  70. titleGroup.getChildren().add(titleVBox);
  71. titleGroup.getChildren().add(titleHBox);
  72.  
  73. Scene scene = new Scene(titleGroup, 500, 500);
  74. primaryStage.setTitle("love u <3");
  75. primaryStage.setScene(scene);
  76. primaryStage.show();
  77.  
  78. }
  79. });
  80. // Button playButton = new Button();
  81. // Button loadButton = new Button();
  82. // Button exitButton = new Button();
  83.  
  84. }
  85.  
  86. // private void saveName() {
  87. //do i need this...
  88. // }
  89.  
  90.  
  91. public static void main(String[] args) {
  92. launch(args);
  93. }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement