Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.stage.Stage;
- public class opening extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception {
- // needs buttons to select what to do and also a text field to store a name
- Label gameTitle = new Label("Basil's Cat Game :3");
- gameTitle.setFont(Font.font(STYLESHEET_CASPIAN, 50));
- Label putNameTxt = new Label("Name:");
- putNameTxt.setFont(Font.font(STYLESHEET_CASPIAN, 30));
- TextField putNameHere = new TextField();
- putNameHere.setMaxSize(500, 500);
- Button nameOkButton = new Button("OK");
- nameOkButton.setMaxSize(20, 10);
- nameOkButton.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent saveName) {
- String nameText = putNameHere.getText();
- File nameFile = new File("NameFile.txt");
- try {
- FileWriter fw = new FileWriter(nameFile);
- fw.write(nameText);
- fw.close();
- } catch (IOException e) {
- Group titleGroup = new Group();
- Label errLbl = new Label("Hello World!");
- titleGroup.getChildren().add(errLbl);
- Scene scene = new Scene(titleGroup, 500, 500);
- primaryStage.setTitle("try again <3");
- primaryStage.setScene(scene);
- primaryStage.show();
- e.printStackTrace();
- }
- VBox titleVBox = new VBox();
- titleVBox.getChildren().add(gameTitle);
- titleVBox.getChildren().add(putNameTxt);
- titleVBox.setMaxSize(250, 250);
- HBox titleHBox = new HBox();
- titleHBox.getChildren().add(putNameHere);
- titleHBox.getChildren().add(nameOkButton);
- titleHBox.setMaxSize(250, 250);
- Group titleGroup = new Group();
- titleGroup.getChildren().add(titleVBox);
- titleGroup.getChildren().add(titleHBox);
- Scene scene = new Scene(titleGroup, 500, 500);
- primaryStage.setTitle("love u <3");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- });
- // Button playButton = new Button();
- // Button loadButton = new Button();
- // Button exitButton = new Button();
- }
- // private void saveName() {
- //do i need this...
- // }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement