Stage::ask()
Asks a question and waits for an answer to be typed in. A box appears at the top of the stage; whatever is typed goes into it until Enter is pressed.
Unlike Scratch, this does not pause anything. Your run() keeps being
called while the question is on screen, so check isAsking() or wait
for getAnswer() to change:
public void run() {
if (!this.isAsking() && this.getAnswer().isEmpty()) {
this.ask("What is your name?");
}
if (!this.getAnswer().isEmpty()) {
this.display("Hello " + this.getAnswer() + "!");
}
}
Syntax
Java
.ask(question)
Scratch
ask [question] and wait
Parameters
| Name | Data Type | Description |
|---|---|---|
| question | String | the question to show |
Return
void