Guest User

Untitled

a guest
Feb 10th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. public class First extends Application {
  2.  
  3. public Stage primaryStage2,primaryStage3;
  4.  
  5. Second v=new Second();
  6.  
  7. @Override
  8. public void start(Stage primaryStage) {
  9.  
  10.  
  11. Button btn = new Button();
  12. btn.setText("Press");
  13.  
  14. this.primaryStage3=primaryStage;
  15.  
  16. btn.setOnAction(new EventHandler<ActionEvent>() {
  17.  
  18. @Override
  19. public void handle(ActionEvent event) {
  20.  
  21. v.open();
  22. }
  23. });
  24.  
  25. StackPane root = new StackPane();
  26. root.getChildren().add(btn);
  27. Scene scene = new Scene(root, 300, 250);
  28. primaryStage.setScene(scene);
  29. primaryStage.show();
  30. }
  31.  
  32.  
  33. public static void main(String[] args) {
  34. launch(args);
  35. }
  36.  
  37.  
  38. }
  39.  
  40. public class Second {
  41.  
  42. Stage primaryStage2;
  43.  
  44. First a=new First();
  45.  
  46. public void open(){
  47.  
  48. primaryStage2=new Stage();
  49. StackPane root = new StackPane();
  50. Scene scene = new Scene(root, 300, 250);
  51. primaryStage2.setScene(scene);
  52. a.primaryStage3.close();
  53. primaryStage2.show();
  54. }
  55. }
  56.  
  57. package application;
  58. import javafx.application.Application;
  59. import javafx.stage.Stage;
  60. import javafx.scene.Scene;
  61. import javafx.scene.control.Button;
  62. import javafx.scene.layout.BorderPane;
  63. public class Main extends Application
  64. {
  65. BorderPane root = new BorderPane();
  66. Button btn=new Button("Click Here");
  67. Stage primaryStage;
  68. Scene scene ;
  69. public Main()
  70. {
  71. btn.setPrefWidth(75);
  72. btn.setPrefHeight(15);
  73.  
  74. btn.setOnAction((e)->
  75. {
  76. SubClass s=new SubClass(primaryStage);
  77. });
  78. }
  79.  
  80. @Override
  81. public void start(Stage primaryStage)
  82. {
  83. try {
  84. this.primaryStage=primaryStage;
  85. // root.getChildren().add(btn);
  86.  
  87. scene = initStage();
  88. scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
  89. primaryStage.setScene(scene);
  90. primaryStage.show();
  91. } catch(Exception e)
  92. {
  93. e.printStackTrace();
  94. }
  95. }
  96.  
  97. private Scene initStage()
  98. {
  99. root.setCenter(btn);
  100. return new Scene(root,150,150);
  101. }
  102.  
  103.  
  104. public static void main(String[] args) {
  105. launch(args);
  106. }
  107. }
  108.  
  109. package application;
  110.  
  111. import javafx.scene.Scene;
  112. import javafx.scene.layout.StackPane;
  113. import javafx.stage.Stage;
  114.  
  115. public class SubClass
  116. {
  117.  
  118. StackPane root = new StackPane();
  119. Stage stage;
  120.  
  121. public SubClass(Stage stage)
  122. {
  123. Scene scene=new Scene(root,300,300);
  124. stage.setScene(scene);
  125. stage.show();
  126. }
  127. }
  128.  
  129. package signIn;
  130. import javafx.application.Application;
  131. import javafx.event.ActionEvent;
  132. import javafx.event.EventHandler;
  133. import javafx.geometry.Insets;
  134. import javafx.geometry.Pos;
  135. import javafx.scene.Scene;
  136. import javafx.scene.control.Alert;
  137. import javafx.scene.control.Alert.AlertType;
  138. import javafx.scene.control.Button;
  139. import javafx.scene.control.Label;
  140. import javafx.scene.control.TextField;
  141. import javafx.scene.layout.StackPane;
  142. import javafx.scene.layout.VBox;
  143. import javafx.stage.Stage;
  144.  
  145. public class JavaFXWindowDemo extends Application {
  146.  
  147. private String loggedInUser;
  148.  
  149. public static void main(String[] args) {
  150. launch(args);
  151. }
  152.  
  153. // How to open a new window in JavaFX
  154. @Override
  155. public void start(Stage primaryStage) throws Exception {
  156. Button btnLogin = new Button();
  157. btnLogin.setText("Login");
  158. btnLogin.setOnAction(new EventHandler<ActionEvent>() {
  159. @Override
  160. public void handle(ActionEvent event) {
  161. showLoginScreen();
  162. }
  163. });
  164. // A layout container for UI controls
  165. StackPane root = new StackPane();
  166. root.getChildren().add(btnLogin);
  167.  
  168. // Top level container for all view content
  169. Scene scene = new Scene(root, 300, 250);
  170.  
  171. // primaryStage is the main top level window created by platform
  172. primaryStage.setTitle("JavaFX Demo");
  173. primaryStage.setScene(scene);
  174. primaryStage.show();
  175. }
  176.  
  177. public void setLoggedInUser(String user) {
  178. loggedInUser = user;
  179.  
  180. Alert alert = new Alert(AlertType.INFORMATION);
  181. alert.setTitle("Successful login");
  182. alert.setHeaderText("Successful login");
  183. String s = user + " logged in!";
  184. alert.setContentText(s);
  185. alert.show();
  186. }
  187.  
  188. public void showLoginScreen() {
  189. Stage stage = new Stage();
  190.  
  191. VBox box = new VBox();
  192. box.setPadding(new Insets(10));
  193.  
  194. // How to center align content in a layout manager in JavaFX
  195. box.setAlignment(Pos.CENTER);
  196.  
  197. Label label = new Label("Enter username and password");
  198.  
  199. TextField textUser = new TextField();
  200. textUser.setPromptText("enter user name");
  201. TextField textPass = new TextField();
  202. textPass.setPromptText("enter password");
  203.  
  204. Button btnLogin = new Button();
  205. btnLogin.setText("Login");
  206.  
  207. btnLogin.setOnAction(new EventHandler<ActionEvent>() {
  208.  
  209. @Override
  210. public void handle(ActionEvent event) {
  211. // Assume success always!
  212. setLoggedInUser(textUser.getText());
  213. stage.close(); // return to main window
  214. }
  215. });
  216.  
  217. box.getChildren().add(label);
  218. box.getChildren().add(textUser);
  219. box.getChildren().add(textPass);
  220. box.getChildren().add(btnLogin);
  221. Scene scene = new Scene(box, 250, 150);
  222. stage.setScene(scene);
  223. stage.show();
  224. }
  225. }
  226.  
  227. public class Second {
  228.  
  229. Stage primaryStage2;
  230.  
  231. First a=new First();
  232.  
  233. public void open(){
  234.  
  235. primaryStage2=new Stage();
  236. StackPane root = new StackPane();
  237. Scene scene = new Scene(root, 300, 250);
  238. primaryStage2.setScene(scene);
  239. a.primaryStage3.close();
  240. primaryStage2.show();
  241. }
  242. }
  243.  
  244. btn.setOnAction(new EventHandler<ActionEvent>() {
  245.  
  246. @Override
  247. public void handle(ActionEvent event) {
  248.  
  249. v.open();
  250. primaryStage3.close(); // new LINE!!
  251. }
  252. });
Add Comment
Please, Sign In to add comment