如何解决检查哪个按钮被点击了 javafx
任何人都可以帮忙,我正在制作一个购买信用的程序。有谁知道如何在交易按钮之前确认点击了名义号码按钮?
我的程序有错误,当我没有点击名义按钮但交易成功我想要的是如果我没有点击名义数字按钮,“选择名义”警报出现
@FXML
private Button fivethsnd;
@FXML
private Button transaction;
static String noHP;
ArrayList<String[]> data = new File().baca();
// method button fivethsnd
public int fivethousand(MouseEvent mouseEvent) {
Node node = (Node) mouseEvent.getTarget();
String tosrtingfivethousand = fivethsnd.getText();
System.out.println(tosrtingfivethousand);
return 1;
}
//method transaction
public void Transaction(MouseEvent event)throws IOException {
Alert settransaction = new Alert(Alert.AlertType.ERROR);
settransaction.setTitle("Something Wrong");
settransaction.setHeaderText(null);
//call the fivethousand method to check the button has been clicked
if (fivethousand(event)==1){
String[] sellpulses = new String[2];
noHP=numberhp.getText();
String digitfirst = "081";
String digit = noHP.substring(0,3);
boolean isNumeric = noHP.chars().allMatch(Character::isDigit);
System.out.println("digit: "+digit);
System.out.println(noHP);
if (noHP.length() == 12 || noHP.length() == 13) {
if (isNumeric) {
if (digit.equals(digitfirst)){
sellpulses[0]=numberhp.getText();
sellpulses[1]= fivethsnd.getText();
data.add(sellpulses);
new File().simpan(data); // save to txt file
}
else {
settransaction.setContentText("The first 3 digits must be 081");
settransaction.showAndWait();
}
} else {
settransaction.setContentText("Mobile number must be a number");
settransaction.showAndWait();
}
} else {
settransaction.setContentText("Nomor HP tidak valid");
settransaction.showAndWait();
}
}else if (limaribu(event)!=1){
settransaction.setContentText("choose nominal first"); // allert when nominal not clicked
settransaction.showAndWait();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。