Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import javafx.application.Application;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.paint.Color;
- import javafx.scene.text.Font;
- import javafx.scene.text.FontPosture;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- public class Login extends Application {
- double d = 0.0;
- @Override
- public void start(Stage primaryStage) throws Exception {
- GridPane grid = new GridPane();
- grid.setAlignment(Pos.CENTER);
- grid.setHgap(10);
- grid.setVgap(10);
- grid.setPadding(new Insets(20, 20, 20, 20));
- grid.setGridLinesVisible(false);
- Scene scene = new Scene(grid, 450, 275);
- primaryStage.setTitle("窗口标题");
- primaryStage.setScene(scene);
- scene.getStylesheets().add(Login.class.getResource("login.css").toExternalForm());
- // 控件 ******************************
- Text sceneTitle = new Text("Welcome");
- sceneTitle.setId("sceneTitle");
- sceneTitle.setFont(Font.font("Consolas", FontPosture.ITALIC, 22));
- grid.add(sceneTitle, 0, 0, 2, 1);
- Label userName = new Label("Username: ");
- grid.add(userName, 0, 1);
- TextField userTextField = new TextField();
- userTextField.setText("root");
- grid.add(userTextField, 1, 1);
- Label pw = new Label("Password:");
- grid.add(pw, 0, 2);
- PasswordField pwBox = new PasswordField();
- grid.add(pwBox, 1, 2);
- Text msg = new Text();
- grid.add(msg, 1, 4);
- Button btn = new Button("Login");
- HBox hbBtn = new HBox(10);
- hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
- hbBtn.getChildren().add(btn);
- btn.setOnMouseClicked(event -> {
- if (userTextField.getText().equalsIgnoreCase("root")) {
- msg.setText("Login success.");
- msg.setFill(Color.GREEN);
- } else {
- msg.setText("Login failed.");
- msg.setFill(Color.RED);
- }
- });
- grid.add(hbBtn, 1, 4);
- ProgressBar pb = new ProgressBar(0);
- ProgressIndicator pi = new ProgressIndicator(0);
- grid.add(pb, 1, 4);
- grid.add(pi, 0, 4);
- /* Timer timer = new Timer();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- if (d > 1) timer.cancel();
- else {
- d = d + 0.10;
- pb.setProgress(d);
- }
- }
- }, 0, 1000);*/
- GridPane window1 = new GridPane();
- window1.setVgap(10);
- window1.setHgap(10);
- Text hello = new Text("Hello");
- hello.setFont(Font.font("Consolas", FontPosture.ITALIC, 20));
- window1.add(hello, 0, 1);
- Scene window = new Scene(window1, 450, 275);
- window.getStylesheets().add(Login.class.getResource("login.css").toExternalForm());
- btn.setOnAction(event -> {
- primaryStage.setTitle("Window");
- primaryStage.setScene(window);
- });
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Add Comment
Please, Sign In to add comment