Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Optional;
- import java.util.Scanner;
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.fxml.FXMLLoader;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Node;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Button;
- import javafx.scene.control.ButtonType;
- import javafx.scene.control.Label;
- import javafx.scene.control.Menu;
- import javafx.scene.control.MenuBar;
- import javafx.scene.control.MenuItem;
- import javafx.scene.control.SeparatorMenuItem;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.scene.control.TextInputDialog;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- public class userInterface extends Application {
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage stage) throws Exception {
- stage.setTitle("Adventure!");
- stage.setResizable(false);
- Menu menu = new Menu("Menu");
- MenuItem ng = new MenuItem("New Game");
- ng.setOnAction(event -> {
- //TODO: restart program
- });
- MenuItem save = new MenuItem("Save");
- MenuItem load = new MenuItem("Load");
- MenuItem help = new MenuItem("Help");
- help.setOnAction(e -> {
- Stage st = new Stage();
- st.setTitle("Help");
- BorderPane bp = new BorderPane();
- bp.setPadding(new Insets(7,7,7,7));
- Button close = new Button("Close");
- BorderPane.setAlignment(close, Pos.CENTER);
- close.setOnAction(event -> {
- st.close();
- });
- bp.setBottom(close);
- TextArea ta = new TextArea();
- ta.setEditable(false);
- bp.setCenter(ta);
- BorderPane.setMargin(ta, new Insets(5,5,5,5));
- File f;
- try {
- f = new File("help.txt");
- Scanner s = new Scanner(f);
- while(s.hasNextLine()) {
- ta.setText(ta.getText() + s.nextLine() + "\n");
- }
- s.close();
- }
- catch(Exception ee) {
- }
- st.setScene(new Scene(bp, 300, 350));
- st.show();
- });
- MenuItem quit = new MenuItem("Quit");
- quit.setOnAction(event -> {
- Alert confirm =
- new Alert(Alert.AlertType.CONFIRMATION,"Do you really want to quit?"
- ,ButtonType.YES, ButtonType.NO);
- confirm.setTitle("Quit Game?");
- confirm.setHeaderText("");
- Optional<ButtonType> response = confirm.showAndWait();
- if ( response.isPresent() && response.get() == ButtonType.YES ) {
- Platform.exit();
- }
- });
- menu.getItems().addAll(ng,new SeparatorMenuItem(),
- save,new SeparatorMenuItem(),
- load,new SeparatorMenuItem(),
- help,new SeparatorMenuItem(),
- quit);
- MenuBar menuBar = new MenuBar();
- menuBar.getMenus().add(menu);
- BorderPane bp = new BorderPane();
- //input text
- TextField tf = new TextField();
- tf.setMinSize(300.0 , 30.0);
- //enter button
- Button enter = new Button("Enter");
- enter.setMinSize(80.0, 30.0);
- //bottom hbox for input
- HBox hBoxBottom = new HBox(tf,enter);
- hBoxBottom.setPadding(new Insets(5,5,5,5));
- HBox.setMargin(enter, new Insets(5,5,5,5));
- HBox.setMargin(tf, new Insets(5,5,5,5));
- //dialog box
- TextArea ta = new TextArea();
- ta.setEditable(false);
- ta.setMaxSize(392.0, 550.0);
- BorderPane.setMargin(ta, new Insets(8,5,0,8));
- //stats
- Label name = new Label("Name: " + "fdsa");
- Label turn = new Label("Turn: " + "1");
- Label health = new Label("Health: " + "100");
- Label mana = new Label("Mana: "+ "100");
- Label pA = new Label("Physical Attack: "+ "100");
- Label pD= new Label("Physical Defense: "+ "100");
- // Label mA= new Label();
- Label Stamina = new Label("Stamina: "+ "100");
- Label Hunger = new Label("Hunger: "+ "100");
- VBox desc = new VBox(name,turn,health,mana,pA,pD,Stamina,Hunger);
- desc.setPadding(new Insets(5,5,5,5));
- VBox.setMargin(name, new Insets(5,5,5,5));
- VBox.setMargin(turn, new Insets(5,5,5,5));
- VBox.setMargin(health, new Insets(5,5,5,5));
- VBox.setMargin(mana, new Insets(5,5,5,5));
- VBox.setMargin(pA, new Insets(5,5,5,5));
- VBox.setMargin(pD, new Insets(5,5,5,5));
- VBox.setMargin(Stamina, new Insets(5,5,5,5));
- VBox.setMargin(Hunger, new Insets(5,5,5,5));
- bp.setTop(menuBar);
- bp.setBottom(hBoxBottom);
- bp.setLeft(ta);
- bp.setCenter(desc);
- Scene scene = new Scene(bp, 700, 600);
- stage.setScene(scene);
- stage.show();
- }
- }
- /*
- public void start ( Stage stage ) throws Exception {
- stage.setTitle("Draw App");
- BorderPane root = new BorderPane();
- root.setStyle("-fx-background-color: firebrick");
- Scene scene = new Scene(root);
- stage.setScene(scene);
- // keep the window from being resized by the user
- stage.setResizable(false);
- HBox canvaspane = new HBox();
- canvaspane
- .setStyle("-fx-border-color: black; -fx-border-width: 1px; -fx-background-color: snow");
- Canvas canvas = new Canvas(400,300);
- // clear(canvas);
- canvas.setOnMousePressed(e -> {
- startX_ = e.getX();
- startY_ = e.getY();
- });
- canvas.setOnMouseReleased(e -> drawRect(canvas,startX_,startY_,e.getX(),
- e.getY()));
- // menu
- MenuBar menuBar = new MenuBar();
- Menu menu = new Menu("Menu");
- MenuItem menuItem1 = new MenuItem("Clear");
- menuItem1.setOnAction(event -> {
- clear(canvas);
- });
- MenuItem menuItem2 = new MenuItem("Quit");
- menuItem2.setOnAction(event -> {
- Alert confirm =
- new Alert(Alert.AlertType.CONFIRMATION,"Do you really want to quit?");
- confirm.setTitle("");
- confirm.setHeaderText("");
- Optional<ButtonType> response = confirm.showAndWait();
- if ( response.isPresent() && response.get() == ButtonType.OK ) {
- Platform.exit();
- }
- });
- MenuItem menuItem3 = new MenuItem("Sign");
- menuItem3.setOnAction(event -> {
- TextInputDialog getNameDialog = new TextInputDialog("");
- getNameDialog.setTitle("");
- getNameDialog.setHeaderText("Enter your name:");
- getNameDialog.setGraphic(null);
- Optional<String> response = getNameDialog.showAndWait();
- if ( response.isPresent() && response.get().trim().length() > 0 ) {
- GraphicsContext g = canvas.getGraphicsContext2D();
- g.setFill(Color.BLACK);
- String name = response.get().trim();
- g.fillText("by " + name,10,290);
- }
- });
- menu.getItems().addAll(menuItem3,new SeparatorMenuItem(),menuItem1,
- new SeparatorMenuItem(),menuItem2);
- menuBar.getMenus().add(menu);
- root.setTop(menuBar);
- canvaspane.getChildren().add(canvas);
- Button clearbtn = new Button("clear");
- clearbtn.setOnAction(e -> clear(canvas));
- root.setCenter(canvaspane);
- root.setBottom(clearbtn);
- BorderPane.setAlignment(clearbtn,Pos.CENTER);
- BorderPane.setMargin(canvaspane,new Insets(5,5,5,5));
- BorderPane.setMargin(clearbtn,new Insets(0,0,5,0));
- stage.show();
- }
- public static void main ( String[] args ) {
- launch(args);
- }
- private void clear ( Canvas canvas ) {
- GraphicsContext g = canvas.getGraphicsContext2D();
- g.clearRect(0,0,canvas.getWidth(),canvas.getHeight());
- }
- private void drawRect ( Canvas canvas, double x1, double y1, double x2,
- double y2 ) {
- GraphicsContext g = canvas.getGraphicsContext2D();
- double x = Math.min(x1,x2), y = Math.min(y1,y2);
- double w = Math.max(x1,x2) - x, h = Math.max(y1,y2) - y;
- g.setFill(Color.LIGHTSTEELBLUE);
- g.fillRect(x,y,w,h);
- g.setStroke(Color.BLACK);
- g.strokeRect(x,y,w,h);
- }
- }
- */
- <3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement