我想從另一個類中調用一個類的void。對象工作正常,但由於某種原因,它沒有完成行動。來自不同類別的訪問方法
我正在製作黑色傑克遊戲,當用戶輸入正確的賭注時,我需要一些按鈕纔會出現。以下是我有:
public static void showButtons(Boolean x) { // to show or hide the buttons
if(x) {
hitButton.setVisible(true);
standButton.setVisible(true);
separator.setVisible(true);
}
else {
hitButton.setVisible(false);
standButton.setVisible(false);
separator.setVisible(false);
}
}
一旦賭注被驗證爲一個整數,它經過這樣的:
private void bdButtonActionPerformed(java.awt.event.ActionEvent evt) { //bdButton is the bet button
...
if(validBet(s)) {
bet = Integer.parseInt(s); // parses input string into an int
System.out.println("bet accepted"); // debug to know if it works this far
NewRound nr = new NewRound();
System.out.println("created object");
nr.newHand(bet);
//showButtons(true); // this works, it changes the buttons, but only from here
}
else {
...
}
}
這裏是newHand方法:
public static void newHand(int bet) {
System.out.println("In newHand"); // debug
BlackJack b = new BlackJack();
b.showButtons(true);
System.out.println("passed showButtons"); // the code gets to here, but buttons are still not visible
}
「呼叫班級的空白」?你正在調用一個方法,但是'void'只是返回類型(意味着該方法不返回值)。你沒有調用返回類型。 – Wyzard