我想制作一个转换不同基础的项目,但我的单选按钮不起作用。我正在制作三个不同的 VBox 来添加按钮,但只有第三列有效。我对 JavaFX 很陌生,所以如果有人能帮助我,我将不胜感激。谢谢!这是我的代码
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;
import java.math.BigInteger;
public class Main extends Application {
private ToggleGroup group;
private TextField txtfield;
private TextField output;
private int base = 10;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
StackPane title = new StackPane();
Text t = new Text("Gib die Basis und die Zahl ein!");
t.setTextAlignment(TextAlignment.CENTER);
title.getChildren().add(t);
FlowPane center = new FlowPane();
center.setPrefSize(400, 300);
HBox input = new HBox();
VBox base1 = new VBox();
VBox base2 = new VBox();
VBox base3 = new VBox();
input.setPrefSize(400, 100);
base1.setPrefSize(50, 150);
base2.setPrefSize(50, 150);
base3.setPrefSize(50, 150);
group = new ToggleGroup();
for (int i = 2; i < 35; i++) {
RadioButton b = new RadioButton(String.valueOf(i));
if (i == 10) {
b.setSelected(true);
}
b.setToggleGroup(group);
b.setOnMouseClicked(mouseEvent -> {
base = Integer.valueOf(b.getText());
update();
});
if (i % 3 == 2) {
base1.getChildren().add(b);
b.setTranslateX(110);
} else if (i % 3 == 0) {
base2.getChildren().add(b);
b.setTranslateX(120);
} else {
base3.getChildren().add(b);
b.setTranslateX(130);
}
}
这是程序应该(并且确实)看起来的样子
缥缈止盈
相关分类