gpt4 book ai didi

java - 如何返回 Pane ?

转载 作者:行者123 更新时间:2023-12-02 09:46:06 27 4
gpt4 key购买 nike

我已经快完成这个程序了。它是其中一种带有事件处理程序和更新总数的工作订单表格。如何返回收到用户输入后更新的总值(value)?我确信我需要在某个地方有一个返回 Pane ,只是不确定在哪里。代码如下:

public class Working_order extends Application {

// Radio buttons
private RadioButton rbNext = new RadioButton("$20");
private RadioButton rbThis = new RadioButton("$12");
private RadioButton rbSome = new RadioButton("$5");

private Label lbDue = new Label("$0.00");

@Override
public void start(Stage primaryStage) {
// Create a pane and set its properties
GridPane pane = new GridPane();

pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
pane.setHgap(5.5);
pane.setVgap(5.5);

// Place nodes in the pane
pane.add(new Label("Item"), 0, 0);
pane.add(tfItem, 1, 0);
pane.add(new Label("Price"), 0, 1);
pane.add(tfPrice, 1, 1);
pane.add(new Label("Quantity"), 0, 2);
pane.add(tfQty, 1, 2);

CheckBox chTaxable = new CheckBox("Taxable?");

pane.add(chTaxable, 1, 3);
// More nodes in a pane
pane.add(new Label("Shipping"), 0, 4);
pane.add(rbNext, 1, 5);
pane.add(new Label("Next Day"), 0, 5);
pane.add(rbThis, 1, 6);
pane.add(new Label("This Week"), 0, 6);
pane.add(rbSome, 1, 7);
pane.add(new Label("Total Due"), 0, 8);
pane.add(lbDue, 1, 8);
pane.add(new Label("Some Day"), 0, 7);

Button btAdd = new Button("Process");
Button btAdd2 = new Button("Reset");

// Toggle group
ToggleGroup group = new ToggleGroup();
rbNext.setToggleGroup(group);
rbThis.setToggleGroup(group);
rbSome.setToggleGroup(group);

btAdd.setOnAction(e -> {
// read textboxes

String sPrice = tfPrice.getText();
double price = Double.parseDouble(sPrice);
int qty = Integer.parseInt(tfQty.getText());
double subTotal = price * qty;
double tax;
if (chTaxable.isSelected()) {
tax = subTotal * 0.07;
} else {
tax = 0;
}

});

pane.add(btAdd, 0, 9);
pane.add(btAdd2, 1, 9);
GridPane.setHalignment(btAdd, HPos.RIGHT);
GridPane.setHalignment(btAdd2, HPos.LEFT);

// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("ShowGridPane"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display
}

public static void main(String[] args) {
launch(args);
}
}

最佳答案

首先,您没有构建文本字段(tfItem、tfPrice、tfQty)。要解决此问题,请添加这些行

TextField tfItem = new TextField();
TextField tfPrice = new TextField();
TextField tfQty = new TextField();

你的问题很简单,在btAdd(处理按钮)事件处理程序中应用公式计算结果后,只需在事件处理程序的末尾添加这一行

lbDue.setText( result + "" );

这将解决您的问题

关于java - 如何返回 Pane ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56641703/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com