Advertisement
Guest User

Untitled

a guest
Sep 6th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. package login;
  2.  
  3. import java.net.MalformedURLException;
  4. import javafx.application.Application;
  5. import javafx.event.ActionEvent;
  6. import javafx.event.EventHandler;
  7. import javafx.geometry.Insets;
  8. import javafx.geometry.Pos;
  9. import javafx.scene.Scene;
  10. import javafx.scene.control.Button;
  11. import javafx.scene.control.Label;
  12. import javafx.scene.control.PasswordField;
  13. import javafx.scene.control.TextField;
  14. import javafx.scene.layout.GridPane;
  15. import javafx.scene.layout.HBox;
  16. import javafx.scene.paint.Color;
  17. import javafx.scene.text.Font;
  18. import javafx.scene.text.FontWeight;
  19. import javafx.scene.text.Text;
  20. import javafx.stage.Stage;
  21.  
  22.  
  23. public class Login extends Application {
  24.  
  25. @Override
  26. public void start(Stage primaryStage) throws MalformedURLException{
  27.  
  28. primaryStage.setTitle("JavaFX Welcome");
  29.  
  30. GridPane grid = new GridPane();
  31. grid.setAlignment(Pos.CENTER);
  32. grid.setHgap(10);
  33. grid.setVgap(10);
  34. grid.setPadding(new Insets(25,25,25,25));
  35.  
  36. Text scenetitle = new Text("Welcome");
  37. scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
  38. grid.add(scenetitle, 0, 0, 2, 1);
  39.  
  40. Label userName = new Label("User Name:");
  41. grid.add(userName, 0, 1);
  42.  
  43. TextField userTextField = new TextField();
  44. grid.add(userTextField, 1, 1);
  45.  
  46. Label pw = new Label("Password:");
  47. grid.add(pw, 0, 2);
  48.  
  49. PasswordField pwBox = new PasswordField();
  50. grid.add(pwBox, 1, 2);
  51.  
  52. Button btn = new Button("Sign in");
  53. HBox hbBtn = new HBox(10);
  54. hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
  55. hbBtn.getChildren().add(btn);
  56. grid.add(hbBtn, 1, 4);
  57.  
  58. final Text actiontarget = new Text();
  59. grid.add(actiontarget, 1, 6);
  60.  
  61. btn.setOnAction(new EventHandler<ActionEvent>()
  62. {
  63. @Override
  64. public void handle(ActionEvent a){
  65. actiontarget.setFill(Color.FIREBRICK);
  66. actiontarget.setText("Sign in button pressed");
  67. }
  68.  
  69. }
  70. );
  71.  
  72.  
  73.  
  74. //grid.setGridLinesVisible(true);
  75. Scene scene = new Scene(grid, 400, 350);
  76. scene.getStylesheets().add(Login.class.getResource("Login.css").toExternalForm());
  77. primaryStage.setScene(scene);
  78.  
  79.  
  80.  
  81. primaryStage.show();
  82.  
  83. }
  84.  
  85.  
  86. /**
  87. * @param args the command line arguments
  88. */
  89. public static void main(String[] args) {
  90. launch(args);
  91. }
  92.  
  93. }
  94.  
  95. .root {
  96. -fx-background-color: #383838;
  97.  
  98. }
  99.  
  100. Exception in Application start method
  101. java.lang.reflect.InvocationTargetException
  102. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  103. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  104. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  105. at java.lang.reflect.Method.invoke(Method.java:498)
  106. at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
  107. at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
  108. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  109. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  110. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  111. at java.lang.reflect.Method.invoke(Method.java:498)
  112. at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  113. Caused by: java.lang.RuntimeException: Exception in Application start method
  114. at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
  115. at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
  116. at java.lang.Thread.run(Thread.java:745)
  117. Caused by: java.lang.NullPointerException
  118. at login.Login.start(Login.java:84)
  119. at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
  120. at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
  121. at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
  122. at java.security.AccessController.doPrivileged(Native Method)
  123. at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
  124. at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
  125. at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  126. at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
  127. ... 1 more
  128. Exception running application login.Login
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement