1 回答

桃花長相依
TA貢獻1860條經驗 獲得超8個贊
您可以添加一個參數化構造函數,該構造函數將對象作為參數并在此構造函數中初始化BTDBattlesBot對象,而不是new在AutomatedActions類中使用關鍵字BTDBattlesBot初始化對象。像下面這樣
public class AutomatedActions {
...............
private final BTDBattlesBot botWindow = null;
// Below is the parametrized constructor
public AutomatedActions(BTDBattlesBot botWindow) {
botWindow = this.botWindow;
}
..........
}
然后在BTDBattlesBot類中,在創建類的對象時AutomatedActions,不調用默認構造函數,而是調用新創建的參數化構造函數,并BTDBattlesBot使用this關鍵字傳遞類的當前對象。通過這樣做,您應該能夠實現您想要的
class BTDBattlesBot {
......
AutomatedActions action = new AutomatedActions(this);
......
}
添加回答
舉報
0/150
提交
取消