Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.60 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.Optional;
  5. import java.util.Scanner;
  6.  
  7. import javafx.application.Application;
  8. import javafx.application.Platform;
  9. import javafx.fxml.FXMLLoader;
  10. import javafx.geometry.Insets;
  11. import javafx.geometry.Pos;
  12. import javafx.scene.Node;
  13. import javafx.scene.Parent;
  14. import javafx.scene.Scene;
  15. import javafx.scene.control.Alert;
  16. import javafx.scene.control.Button;
  17. import javafx.scene.control.ButtonType;
  18. import javafx.scene.control.Label;
  19. import javafx.scene.control.Menu;
  20. import javafx.scene.control.MenuBar;
  21. import javafx.scene.control.MenuItem;
  22. import javafx.scene.control.SeparatorMenuItem;
  23. import javafx.scene.control.TextArea;
  24. import javafx.scene.control.TextField;
  25. import javafx.scene.control.TextInputDialog;
  26. import javafx.scene.layout.BorderPane;
  27. import javafx.scene.layout.HBox;
  28. import javafx.scene.layout.VBox;
  29. import javafx.stage.Stage;
  30.  
  31. public class userInterface extends Application {
  32.  
  33. public static void main(String[] args) {
  34. launch(args);
  35. }
  36.  
  37. @Override
  38. public void start(Stage stage) throws Exception {
  39.  
  40. stage.setTitle("Adventure!");
  41. stage.setResizable(false);
  42.  
  43. Menu menu = new Menu("Menu");
  44.  
  45. MenuItem ng = new MenuItem("New Game");
  46. ng.setOnAction(event -> {
  47. //TODO: restart program
  48. });
  49. MenuItem save = new MenuItem("Save");
  50. MenuItem load = new MenuItem("Load");
  51. MenuItem help = new MenuItem("Help");
  52. help.setOnAction(e -> {
  53.  
  54. Stage st = new Stage();
  55. st.setTitle("Help");
  56. BorderPane bp = new BorderPane();
  57. bp.setPadding(new Insets(7,7,7,7));
  58. Button close = new Button("Close");
  59. BorderPane.setAlignment(close, Pos.CENTER);
  60. close.setOnAction(event -> {
  61. st.close();
  62. });
  63.  
  64. bp.setBottom(close);
  65. TextArea ta = new TextArea();
  66. ta.setEditable(false);
  67. bp.setCenter(ta);
  68. BorderPane.setMargin(ta, new Insets(5,5,5,5));
  69.  
  70. File f;
  71. try {
  72. f = new File("help.txt");
  73. Scanner s = new Scanner(f);
  74. while(s.hasNextLine()) {
  75. ta.setText(ta.getText() + s.nextLine() + "\n");
  76. }
  77. s.close();
  78. }
  79. catch(Exception ee) {
  80. }
  81.  
  82. st.setScene(new Scene(bp, 300, 350));
  83. st.show();
  84.  
  85. });
  86. MenuItem quit = new MenuItem("Quit");
  87. quit.setOnAction(event -> {
  88. Alert confirm =
  89. new Alert(Alert.AlertType.CONFIRMATION,"Do you really want to quit?"
  90. ,ButtonType.YES, ButtonType.NO);
  91. confirm.setTitle("Quit Game?");
  92. confirm.setHeaderText("");
  93. Optional<ButtonType> response = confirm.showAndWait();
  94. if ( response.isPresent() && response.get() == ButtonType.YES ) {
  95. Platform.exit();
  96. }
  97. });
  98.  
  99. menu.getItems().addAll(ng,new SeparatorMenuItem(),
  100. save,new SeparatorMenuItem(),
  101. load,new SeparatorMenuItem(),
  102. help,new SeparatorMenuItem(),
  103. quit);
  104.  
  105. MenuBar menuBar = new MenuBar();
  106. menuBar.getMenus().add(menu);
  107.  
  108. BorderPane bp = new BorderPane();
  109.  
  110.  
  111. //input text
  112. TextField tf = new TextField();
  113. tf.setMinSize(300.0 , 30.0);
  114.  
  115. //enter button
  116. Button enter = new Button("Enter");
  117. enter.setMinSize(80.0, 30.0);
  118.  
  119. //bottom hbox for input
  120. HBox hBoxBottom = new HBox(tf,enter);
  121. hBoxBottom.setPadding(new Insets(5,5,5,5));
  122. HBox.setMargin(enter, new Insets(5,5,5,5));
  123. HBox.setMargin(tf, new Insets(5,5,5,5));
  124.  
  125. //dialog box
  126. TextArea ta = new TextArea();
  127. ta.setEditable(false);
  128. ta.setMaxSize(392.0, 550.0);
  129. BorderPane.setMargin(ta, new Insets(8,5,0,8));
  130.  
  131. //stats
  132. Label name = new Label("Name: " + "fdsa");
  133. Label turn = new Label("Turn: " + "1");
  134. Label health = new Label("Health: " + "100");
  135. Label mana = new Label("Mana: "+ "100");
  136. Label pA = new Label("Physical Attack: "+ "100");
  137. Label pD= new Label("Physical Defense: "+ "100");
  138. // Label mA= new Label();
  139. Label Stamina = new Label("Stamina: "+ "100");
  140. Label Hunger = new Label("Hunger: "+ "100");
  141. VBox desc = new VBox(name,turn,health,mana,pA,pD,Stamina,Hunger);
  142. desc.setPadding(new Insets(5,5,5,5));
  143. VBox.setMargin(name, new Insets(5,5,5,5));
  144. VBox.setMargin(turn, new Insets(5,5,5,5));
  145. VBox.setMargin(health, new Insets(5,5,5,5));
  146. VBox.setMargin(mana, new Insets(5,5,5,5));
  147. VBox.setMargin(pA, new Insets(5,5,5,5));
  148. VBox.setMargin(pD, new Insets(5,5,5,5));
  149. VBox.setMargin(Stamina, new Insets(5,5,5,5));
  150. VBox.setMargin(Hunger, new Insets(5,5,5,5));
  151.  
  152.  
  153.  
  154. bp.setTop(menuBar);
  155. bp.setBottom(hBoxBottom);
  156. bp.setLeft(ta);
  157. bp.setCenter(desc);
  158.  
  159. Scene scene = new Scene(bp, 700, 600);
  160.  
  161. stage.setScene(scene);
  162. stage.show();
  163. }
  164.  
  165. }
  166.  
  167.  
  168. /*
  169.  
  170. public void start ( Stage stage ) throws Exception {
  171. stage.setTitle("Draw App");
  172.  
  173. BorderPane root = new BorderPane();
  174. root.setStyle("-fx-background-color: firebrick");
  175. Scene scene = new Scene(root);
  176. stage.setScene(scene);
  177. // keep the window from being resized by the user
  178. stage.setResizable(false);
  179.  
  180. HBox canvaspane = new HBox();
  181. canvaspane
  182. .setStyle("-fx-border-color: black; -fx-border-width: 1px; -fx-background-color: snow");
  183.  
  184. Canvas canvas = new Canvas(400,300);
  185. // clear(canvas);
  186. canvas.setOnMousePressed(e -> {
  187. startX_ = e.getX();
  188. startY_ = e.getY();
  189. });
  190. canvas.setOnMouseReleased(e -> drawRect(canvas,startX_,startY_,e.getX(),
  191. e.getY()));
  192.  
  193. // menu
  194. MenuBar menuBar = new MenuBar();
  195. Menu menu = new Menu("Menu");
  196.  
  197. MenuItem menuItem1 = new MenuItem("Clear");
  198. menuItem1.setOnAction(event -> {
  199. clear(canvas);
  200. });
  201.  
  202. MenuItem menuItem2 = new MenuItem("Quit");
  203. menuItem2.setOnAction(event -> {
  204. Alert confirm =
  205. new Alert(Alert.AlertType.CONFIRMATION,"Do you really want to quit?");
  206. confirm.setTitle("");
  207. confirm.setHeaderText("");
  208. Optional<ButtonType> response = confirm.showAndWait();
  209. if ( response.isPresent() && response.get() == ButtonType.OK ) {
  210. Platform.exit();
  211. }
  212. });
  213.  
  214. MenuItem menuItem3 = new MenuItem("Sign");
  215. menuItem3.setOnAction(event -> {
  216. TextInputDialog getNameDialog = new TextInputDialog("");
  217. getNameDialog.setTitle("");
  218. getNameDialog.setHeaderText("Enter your name:");
  219. getNameDialog.setGraphic(null);
  220. Optional<String> response = getNameDialog.showAndWait();
  221. if ( response.isPresent() && response.get().trim().length() > 0 ) {
  222. GraphicsContext g = canvas.getGraphicsContext2D();
  223. g.setFill(Color.BLACK);
  224. String name = response.get().trim();
  225. g.fillText("by " + name,10,290);
  226. }
  227. });
  228.  
  229. menu.getItems().addAll(menuItem3,new SeparatorMenuItem(),menuItem1,
  230. new SeparatorMenuItem(),menuItem2);
  231.  
  232. menuBar.getMenus().add(menu);
  233. root.setTop(menuBar);
  234.  
  235. canvaspane.getChildren().add(canvas);
  236.  
  237. Button clearbtn = new Button("clear");
  238. clearbtn.setOnAction(e -> clear(canvas));
  239.  
  240. root.setCenter(canvaspane);
  241. root.setBottom(clearbtn);
  242.  
  243. BorderPane.setAlignment(clearbtn,Pos.CENTER);
  244. BorderPane.setMargin(canvaspane,new Insets(5,5,5,5));
  245. BorderPane.setMargin(clearbtn,new Insets(0,0,5,0));
  246.  
  247. stage.show();
  248. }
  249.  
  250. public static void main ( String[] args ) {
  251. launch(args);
  252. }
  253.  
  254. private void clear ( Canvas canvas ) {
  255. GraphicsContext g = canvas.getGraphicsContext2D();
  256. g.clearRect(0,0,canvas.getWidth(),canvas.getHeight());
  257. }
  258.  
  259. private void drawRect ( Canvas canvas, double x1, double y1, double x2,
  260. double y2 ) {
  261. GraphicsContext g = canvas.getGraphicsContext2D();
  262.  
  263. double x = Math.min(x1,x2), y = Math.min(y1,y2);
  264. double w = Math.max(x1,x2) - x, h = Math.max(y1,y2) - y;
  265.  
  266. g.setFill(Color.LIGHTSTEELBLUE);
  267. g.fillRect(x,y,w,h);
  268. g.setStroke(Color.BLACK);
  269. g.strokeRect(x,y,w,h);
  270. }
  271.  
  272. }
  273.  
  274.  
  275. */
  276.  
  277.  
  278. <3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement