2024/06/23笔记随笔

  • 创建文本输入框:````plaintext
    TextField textField=new TextField();
    textField.setPromptText("请输入文字");//提示信息
    textField.setMaxWidth(100);
* 设置按钮的点击事件处理器:
  ````plaintext
//创建按钮的点击事件处理器
        Button button=new Button("Click me");
        button.setOnAction(event ->{System.out.println("Button clicked");});
  • 获取文本输入内容:

button.setOnAction(event ->{
//获取文本输入内容
String text=textField.getText();
System.out.println(text);
});

* 显示提示信息:
  ````plaintext
button.setOnAction(event ->{
            //获取文本输入内容
            String text=textField.getText();
            System.out.println(text);
            //显示提示信息
            Alert alert=new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("Ti shi");
            alert.setHeaderText("你输入的信息是"+text);
            alert.showAndWait();
        });
  • 选择相应操作:

button.setOnAction(event -> {
//获取文本输入框内容
String text = textField.getText();

        // 创建一个确认对话框
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "您确定要继续吗?",
                ButtonType.OK, ButtonType.CANCEL);
        // 显示对话框并等待用户的选择
        ButtonType result = alert.showAndWait().orElse(ButtonType.CANCEL);

        // 根据用户的选择执行相应的操作
        if (result == ButtonType.OK) {
            System.out.println("用户点击了'确定'");
            // 在这里执行需要的操作
        } else {
            System.out.println("用户点击了'取消'或关闭了对话框");
            // 在这里执行需要的操作
        }
    });
posted @   ZxKing  阅读(3)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示