I am trying to settext
to JLabel
with a function.
The checkResults function is not working for some reason I still get errors. I have 2 classe
Okay, this
jl.setText.(answers.checkResult());
should be this:
jl.setText(answers.checkResult(expected));
this:
public String checkResult(final int answer) {
return Integer.toString(expected);
}
should be something like this:
public int getAnswer() {
return expected;
}
NOW here's the REAL issue
You shouldn't be doing this:
String s = in.nextLine();
You should add a textbox to the form to enter the value, that's why it's freezing on you. Scanner is used for command line input output
Change this:
String s = in.nextLine();
int expected = Integer.parseInt(s);
to
int expected = problems.getAnswer();
I think jl.setText requires a string a string value instead of passing an integer.
In your case perhaps
jl.setText(answers.checkResult(Integer.toString(expected)));
and change
public String checkResult(String answer) {
return Integer.toString(expected);
}
Although Im not entirely sure what you are trying to achieve here
As I commented on your previous question: You need to remove "problems.run()" from your first condition in the listener, otherwise the "answer" you get will be for the next question, and so on. Also, consider using doubles in your divide() method, by using ints you will lose the decimals.
The solution to this problem is expected needs to be
@Override
public String toString(){
return Integer.toString(expected);
}
Then it needs to be set to JLabel like this,
jl.setText(problems.toString());