im currently trying to create a program that dynamically changes the text on JTextArea's and JButtons when they are pressed, or display a JOptionPane. At the moment nothing is happening when i press the buttons, they are not getting updated nor are they making a dialogue box appear.
Help is appreciated private MillionaireGui view; private Millionaire model; private String question; private int gameState; private boolean isRunning;
public MillionaireController(MillionaireGui view, Millionaire model) {
this.view = view;
this.model = model;
this.question = null;
this.gameState = 0;
this.isRunning = true;
}
public void setModel(Millionaire model) {
this.model = model;
}
public void setView(MillionaireGui gui) {
this.view = gui;
}
public void getQuestion() {
question = model.getDeck().generateQuestion();
view.setQuestion(question);
}
public void update(){
while(isRunning){
if(gameState == 0){
getQuestion();
ArrayList<String> ans = model.getDeck().getAnswers();
view.setButtonA(ans.get(0));
view.setButtonB(ans.get(1));
view.setButtonC(ans.get(2));
view.setButtonD(ans.get(3));
gameState = 1;
}
if(gameState == 1){
if(view.getAnswer() != 0){
if(model.getDeck().isCorrect(view.getAnswer())){
view.dispCorrectAnswer();
view.setAnswer(0);
gameState = 0;
}
else {
gameState = 3;
}
}
}
if(gameState == 3){
isRunning = false;
view.displayErrorMsg();
}
}
}
@Override
public void run() {
update();
}
GUI:
public void setButtonB(String str){
buttonB.setText(str);
}
public void setButtonC(String str){
buttonC.setText(str);
}
public void setButtonD(String str){
buttonD.setText(str);
}
public void setAnswer(int num){
answer = num;
}
public String getQuestion(){
return question;
}
public void setQuestion(String str){
question = str;
questionField.setText(str);
}
MAIN:
public class Millionaire_main {
public Millionaire_main(){
}
public static void main(String[] args) {
MillionaireGui gui = new MillionaireGui();
QuestionDeck deck = new QuestionDeck();
Millionaire model = new Millionaire(deck);
MillionaireController control = new MillionaireController(gui, model);
gui.setVisible(true);
Thread thread = new Thread(control);
thread.start();
}
}