我在BankAccount类中有2个字段文本,其中1个用于存款,1个用于提取。
两个字段文本都仅取双值:
TextField depositInput = new TextField();
TextField withdrawInput = new TextField();
和1个按钮来执行这些字段文本(可以是两个)。
Button button = new Button("Execute");
问题是我不知道如何告诉Java已执行哪个TextField。由于我想在用户想要存入或提取时显示不同的消息:
例如:
if(FieldText executed is deposit){
println("User deposits X amount");
double depositAmount = X;
}
if(FieldText executed is withdraw){
println("User withdraws X amount");
double withdrawAmount = -X;
}
我尝试过:
if(FieldText == depositInput){
}
但是Java向我显示了一个错误。
答案 0 :(得分:1)
如果我的问题没错,最简单的解决方案是仅在按下按钮时检查文本字段的值是否为空:
TextField depositInput = new TextField();
TextField withdrawInput = new TextField();
Button button = new Button("Execute");
button.setOnAction((event) -> {
if (!depositInput.getText().isEmpty() && !withdrawInput.getText().isEmpty()) {
System.out.println("Deposit&Withdrawal");
} else if (!depositInput.getText().isEmpty()) {
System.out.println("Deposit");
} else if (!withdrawInput.getText().isEmpty()) {
System.out.println("Withdrawal");
}
});
答案 1 :(得分:0)
如果您正在使用JavaFX和场景构建器
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
multiclass = np.array([[44.70, 30.83, 21.40, 2.67, 0.40],
[12.17, 64.10, 5.19, 18.34,0.21],
[11.63, 15.95, 43.64, 18.75, 10.02],
[4.89, 24.19, 14.32, 52.97, 3.53],
[0.00, 1.09, 5.38, 17.49, 76.03]])
class_names = ['apple','orange', 'tomato', 'melon', 'mango']
df_cm = pd.DataFrame(
multiclass, index=class_names, columns=class_names,
)
fig = plt.figure(figsize=(10,7))
try:
heatmap = sns.heatmap(df_cm, annot=True, fmt="d")
except ValueError:
raise ValueError("Confusion matrix values must be integers.")
heatmap.yaxis.set_ticklabels(heatmap.yaxis.get_ticklabels(), rotation=0, ha='right', fontsize=14)
heatmap.xaxis.set_ticklabels(heatmap.xaxis.get_ticklabels(), rotation=45, ha='right', fontsize=14)
plt.ylabel('True label')
plt.xlabel('Predicted label')