【无标题】注册登录的一些尝试

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class AccountView {

    private Stage primaryStage;
    private TextField accountField;
    private PasswordField passwordField;
    private RadioButton parentRadio;
    private RadioButton kidRadio;
    private Button loginButton;
    private Button signUpButton;

    public AccountView(Stage primaryStage) {
        this.primaryStage = primaryStage;
        initUI();
    }

    private void initUI() {
        // 创建布局
        VBox root = new VBox(10);
        root.setPadding(new Insets(15, 15, 15, 15));
        
        // 应用程序标题
        Label titleLabel = new Label("儿童虚拟银行应用程序");
        titleLabel.setStyle("-fx-font-size: 20px; -fx-font-weight: bold;");
        
        // 表单元素的网格
        GridPane formGrid = new GridPane();
        formGrid.setAlignment(Pos.CENTER);
        formGrid.setHgap(10);
        formGrid.setVgap(10);

        // 账户字段
        Label accountLabel = new Label("账户:");
        accountField = new TextField();
        formGrid.add(accountLabel, 0, 0);
        formGrid.add(accountField, 1, 0);

        // 密码字段
        Label passwordLabel = new Label("密码:");
        passwordField = new PasswordField();
        formGrid.add(passwordLabel, 0, 1);
        formGrid.add(passwordField, 1, 1);

        // 用户类型的单选按钮
        parentRadio = new RadioButton("我是家长");
        kidRadio = new RadioButton("我是孩子");
        ToggleGroup userTypeGroup = new ToggleGroup();
        parentRadio.setToggleGroup(userTypeGroup);
        kidRadio.setToggleGroup(userTypeGroup);
        kidRadio.setSelected(true);

        HBox radioBox = new HBox(10, parentRadio, kidRadio);
        radioBox.setAlignment(Pos.CENTER);
        
        // 登录和注册按钮
        loginButton = new Button("登录");
        signUpButton = new Button("注册");
        HBox buttonBox = new HBox(10, signUpButton, loginButton);
        buttonBox.setAlignment(Pos.CENTER);

        // 将所有组件添加到root
        root.getChildren().addAll(titleLabel, formGrid, radioBox, buttonBox);

        // 创建场景并设置到舞台上
        Scene scene = new Scene(root, 350, 250);
        primaryStage.setTitle("登录");
        primaryStage.setScene(scene);

        // 事件处理(示例处理程序)
        loginButton.setOnAction(event -> System.out.println("点击了登录按钮"));
        signUpButton.setOnAction(event -> System.out.println("点击了注册按钮"));
    }

    public void show() {
        primaryStage.show();
    }

    // 与控制器交互的其他方法
    public String getAccount() {
        return accountField.getText();
    }

    public String getPassword() {
        return passwordField.getText();
    }

    public boolean isParentSelected() {
        return parentRadio.isSelected();
    }

    public boolean isKidSelected() {
        return kidRadio.isSelected();
    }
    
    // ... 根据需要添加更多交互方法
}
//

Certainly! Based on your provided prototype for a signup interface, here is how you might implement the `AccountView.java` for the views layer in a JavaFX application using the MVC pattern:

```java
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class AccountView {

    private Stage primaryStage;
    private RadioButton parentRadio;
    private RadioButton kidRadio;
    private TextField nameField;
    private TextField wechatField;
    private TextField phoneField;
    private TextField qqField;
    private TextField emailField;
    private TextField idField;
    private PasswordField passwordField;
    private PasswordField confirmPasswordField;
    private Button signUpButton;

    public AccountView(Stage primaryStage) {
        this.primaryStage = primaryStage;
        initUI();
    }

    private void initUI() {
        // Create layout
        VBox root = new VBox(10);
        root.setPadding(new Insets(15, 15, 15, 15));
        root.setAlignment(Pos.CENTER);

        // User Info Section
        GridPane userInfoGrid = new GridPane();
        userInfoGrid.setAlignment(Pos.CENTER);
        userInfoGrid.setHgap(10);
        userInfoGrid.setVgap(10);
        userInfoGrid.setPadding(new Insets(20, 10, 20, 10));

        parentRadio = new RadioButton("parent");
        kidRadio = new RadioButton("kid");
        ToggleGroup userTypeGroup = new ToggleGroup();
        parentRadio.setToggleGroup(userTypeGroup);
        kidRadio.setToggleGroup(userTypeGroup);
        kidRadio.setSelected(true); // Default selection
        
        nameField = new TextField();
        wechatField = new TextField();
        phoneField = new TextField();
        qqField = new TextField();
        emailField = new TextField();

        // Add components to userInfoGrid
        userInfoGrid.add(new Label("I am*"), 0, 0);
        userInfoGrid.add(parentRadio, 1, 0);
        userInfoGrid.add(kidRadio, 2, 0);
        userInfoGrid.add(new Label("Name*"), 0, 1);
        userInfoGrid.add(nameField, 1, 1, 2, 1);
        userInfoGrid.add(new Label("Wechat"), 0, 2);
        userInfoGrid.add(wechatField, 1, 2, 2, 1);
        userInfoGrid.add(new Label("Phone number*"), 0, 3);
        userInfoGrid.add(phoneField, 1, 3, 2, 1);
        userInfoGrid.add(new Label("QQ"), 0, 4);
        userInfoGrid.add(qqField, 1, 4, 2, 1);
        userInfoGrid.add(new Label("E-mail"), 0, 5);
        userInfoGrid.add(emailField, 1, 5, 2, 1);

        // Account Info Section
        GridPane accountInfoGrid = new GridPane();
        accountInfoGrid.setAlignment(Pos.CENTER);
        accountInfoGrid.setHgap(10);
        accountInfoGrid.setVgap(10);
        accountInfoGrid.setPadding(new Insets(20, 10, 20, 10));

        idField = new TextField();
        passwordField = new PasswordField();
        confirmPasswordField = new PasswordField();
        signUpButton = new Button("Sign up");

        // Add components to accountInfoGrid
        accountInfoGrid.add(new Label("Id*"), 0, 0);
        accountInfoGrid.add(idField, 1, 0);
        accountInfoGrid.add(new Label("Password *"), 0, 1);
        accountInfoGrid.add(passwordField, 1, 1);
        accountInfoGrid.add(new Label("Confirm Password"), 0, 2);
        accountInfoGrid.add(confirmPasswordField, 1, 2);
        accountInfoGrid.add(signUpButton, 1, 3);

        // Combine both sections
        root.getChildren().addAll(userInfoGrid, accountInfoGrid);

        // Create scene and set it on stage
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Sign Up");

        // Event handling (dummy handlers for demonstration)
        signUpButton.setOnAction(event -> System.out.println("Sign Up button clicked"));
    }

    public void show() {
        primaryStage.show();
    }

    // Methods to interact with the controller (getters)
    public String getName() {
        return nameField.getText();
    }

    public String getWechat() {
        return wechatField.getText();
    }

    public String getPhone() {
        return phoneField.getText();
    }

    public String getQQ() {
        return qqField.getText();
    }

    public String getEmail() {
        return emailField.getText();
    }

    public String getId() {
        return idField.getText();
    }

    public String getPassword() {
        return passwordField

.getText();
    }

    public String getConfirmPassword() {
        return confirmPasswordField.getText();
    }

    public boolean isParentSelected() {
        return parentRadio.isSelected();
    }

    // ... Additional methods and validation as needed
}
```

This code creates the signup form based on the provided prototype and includes fields for user information and account information, as well as a button to submit the form. Event handling and input validation logic should be added according to your application's requirements and will likely involve communication with a controller class to process the signup.

///

在JavaFX中,当用户点击登录界面上的注册按钮时,你通常会打开一个新的窗口(Stage)或者在当前窗口加载一个新的场景(Scene)。以下是如何实现这种逻辑的示例代码。

首先,这是登录界面中注册按钮事件处理的示例代码:

```java
// 在登录界面 AccountView.java 中的 initUI 方法里
signUpButton.setOnAction(event -> openSignUpView());

// ...

private void openSignUpView() {
    // 这里是打开注册界面的代码
    // 你可以选择创建一个新的窨口,或者在当前窗口中切换场景

    // 创建注册视图的实例
    SignUpView signUpView = new SignUpView(primaryStage);
    signUpView.show();
}
```

然后,这是一个简单的注册视图 `SignUpView.java` 的框架代码:

```java
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SignUpView {

    private Stage stage;

    public SignUpView(Stage stage) {
        this.stage = stage;
    }

    public void show() {
        VBox root = new VBox(10);
        Button backButton = new Button("Back to Login");
        // 添加更多注册相关的控件和布局...

        backButton.setOnAction(event -> backToLogin());

        root.getChildren().add(backButton);
        Scene scene = new Scene(root, 300, 300);
        stage.setScene(scene);
        stage.setTitle("Sign Up");
        stage.show();
    }

    private void backToLogin() {
        // 创建登录视图的实例,并显示登录场景
        AccountView accountView = new AccountView(stage);
        accountView.show();
    }
}
```

在这个代码中,`SignUpView` 是另一个视图类,它会在同一个`Stage`上加载一个新的`Scene`,从而实现从登录到注册界面的切换。相应地,注册界面上的返回按钮会重新加载登录界面。

请注意,这里的`SignUpView`和`AccountView`都需要一个`Stage`对象的引用,这样它们就可以在相同的应用程序窗口中切换显示内容。如果你希望在不同窗口中打开注册界面,你可以创建一个新的`Stage`对象而不是重用现有的。这将取决于你的应用程序设计和用户体验需求。

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值