Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. package ca.uwo.eng.se2205b.lab01;/**
  2. * Created by Ammar on 2017-02-03.
  3. */
  4.  
  5. import javafx.application.Application;
  6. import javafx.event.ActionEvent;
  7. import javafx.event.EventHandler;
  8. import javafx.geometry.Insets;
  9. import javafx.geometry.Pos;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.Label;
  13. import javafx.scene.control.PasswordField;
  14. import javafx.scene.control.TextField;
  15. import javafx.scene.input.MouseEvent;
  16. import javafx.scene.layout.GridPane;
  17. import javafx.scene.layout.HBox;
  18. import javafx.scene.paint.Color;
  19. import javafx.scene.text.Font;
  20. import javafx.scene.text.FontWeight;
  21. import javafx.scene.text.Text;
  22. import javafx.stage.Stage;
  23.  
  24. //import javax.xml.soap.Text;
  25. import java.awt.*;
  26.  
  27. public class LoginScreen extends Application {
  28.  
  29. public static void main(String[] args) {
  30. launch(args);
  31. }
  32.  
  33. @Override
  34. public void start(Stage primaryStage) {
  35. primaryStage.setTitle("JavaFX Welcome");
  36.  
  37. GridPane grid = new GridPane();
  38. grid.setAlignment(Pos.CENTER);
  39. grid.setHgap(10);
  40. grid.setVgap(10);
  41. grid.setPadding(new Insets(25, 25, 25, 25));
  42.  
  43. javafx.scene.text.Text scenetitle = new javafx.scene.text.Text("Welcome");
  44. scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
  45. grid.add(scenetitle, 0, 0, 2, 1);
  46.  
  47. Label userName = new Label("User Name:");
  48. grid.add(userName,0, 1);
  49.  
  50. TextField userTextField = new TextField();
  51. grid.add(userTextField, 1, 1);
  52.  
  53. Label pw = new Label("Password:");
  54. grid.add(pw, 0, 2);
  55.  
  56. PasswordField pwBox = new PasswordField();
  57. grid.add(pwBox, 1, 2);
  58.  
  59. Button btn = new Button("Sign in");
  60. HBox hbBtn = new HBox(10);
  61. hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
  62. hbBtn.getChildren().add(btn);
  63. grid.add(hbBtn, 1, 4);
  64.  
  65. final Text actiontarget = new Text();
  66. grid.add(actiontarget, 1, 6);
  67.  
  68.  
  69. grid.setOnMouseClicked(new EventHandler<MouseEvent>() {
  70. @Override
  71. public void handle(MouseEvent event) {
  72. actiontarget.setText("");
  73. }
  74. });
  75.  
  76.  
  77. btn.setOnAction(new EventHandler<ActionEvent>() {
  78.  
  79. @Override
  80. public void handle(ActionEvent e) {
  81.  
  82. if (userTextField.getText().equals("admin") && pwBox.getText().equals("hunter2"))
  83. {
  84. actiontarget.setFill(Color.GREEN);
  85. actiontarget.setText("Login Succesful");
  86. }
  87. else
  88. {
  89. actiontarget.setFill(Color.FIREBRICK);
  90. actiontarget.setText("Login Unsuccessful");
  91. }
  92.  
  93. }
  94. });
  95.  
  96. Scene scene = new Scene(grid, 300, 275);
  97. primaryStage.setScene(scene);
  98. primaryStage.show();
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement