Option Dialogs
Overview
Many programs need to ask a quick yes or no question before they do
something: "Delete this file?", "Quit without saving?", "Start a new game?"
Quorum has a ready-made dialog for this, called an option dialog. It
shows one question with a Yes button and a No button. You don't have to
build its layout. You give it the question and tell it what to do when the
person picks Yes. In this tutorial, you will ask a question with an
OptionDialog from a button on a page, react to Yes and to No, and test
what the dialog is like to use with a keyboard.
Goals
You have the following goals for this tutorial:
By the end of this lesson, you can
- Create an
OptionDialogand set its question withSetLabelTitle - Run your own code when the person picks Yes, with
SetBehavior - Run your own code when the person picks No, with
SetCancelBehavior - Explain when a program should ask before it acts
- Recognize how a fake warning dialog tricks people, and design honest ones
Warm up
Programs ask "Are you sure?" all the time. Think of one time this saved you from a mistake, and one time it just got in your way. What was different about the two? Make a short list of actions that should ask first, and actions that should not.
Vocabulary
You will be learning about the following vocabulary words:
| Term | Definition |
|---|---|
| Option dialog | A ready-made dialog that asks one yes or no question. |
| Confirmation | Asking a person to agree before a program does something that is hard to undo. |
| Cancel | Choosing not to go ahead. In an option dialog, the No button cancels. |
| Modal | A modal dialog blocks the rest of the program until it is closed. Option dialogs are always modal. |
New Code to Learn
You will be using the following new pieces of code:
| Quorum Code | Code Example | Explanation |
|---|---|---|
| OptionDialog | OptionDialog dialog | Creates a dialog with a question, a Yes button and a No button. It is modal. |
| SetLabelTitle(text title) | dialog:SetLabelTitle("Start a new game?") | Sets the question the dialog shows. It also names the dialog for screen readers. |
| SetBehavior(Behavior behavior) | dialog:SetBehavior(yesBehavior) | Sets the behavior that runs when the person picks Yes. |
| SetCancelBehavior(Behavior behavior) | dialog:SetCancelBehavior(noBehavior) | Sets the behavior that runs when the person picks No. By default No just closes the dialog. |
| Show() | question:Show() | Opens the dialog. |
| Hide() | dialog:Hide() | Closes the dialog. Your Yes behavior should call it when it is done. |
CSTA Standards
This tutorial covers the following CSTA standards:
For teachers · 2026 CSTA K–12 Computer Science Standards
High School · Programming
Refine a computing technology based on user feedback, testing results, and responsible design values to improve its effectiveness and impact.
Also in 4 other lessons
Middle School · Programming
Refine a computing technology based on user feedback to improve its usability and accessibility.
Also in 7 other lessons
Specialty I · Software Development
Create software that serves intended users and contexts using human-centered design principles.
Also in 3 other lessons
Middle School · Systems & Security
Evaluate common types of cyber attacks and preventions.
Only this lesson so far
High School · Systems & Security
Classify the causes and impacts of security breaches and social engineering attacks for individuals, industries, communities, and governments.
Only this lesson so far
Explore
What an option dialog is
An OptionDialog is a kind of Dialog that Quorum has already built for
you. (The Dialogs tutorial shows how to build
your own.) It comes with:
- a question, which says "Are you sure?" until you change it;
- a No button, which closes the dialog;
- a Yes button, which runs the behavior you give it;
- a top bar with the dialog's name and an X button.
It is always modal: while it is open, the rest of the program ignores the mouse and keyboard.
Asking a question
In this program, a "New Game" button on the page asks before it sets the score back to 0.
First, add a class named YesBehavior.quorum. It runs when the person
picks Yes. It sets the score label back to 0, then closes the dialog.
use Libraries.Interface.Behaviors.Behavior
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.OptionDialog
use Libraries.Game.Graphics.Label
class YesBehavior is Behavior
OptionDialog dialog = undefined
Label score = undefined
action SetDialog(OptionDialog dialog)
me:dialog = dialog
end
action SetScoreLabel(Label score)
me:score = score
end
action Run(BehaviorEvent event)
score:SetText("Score: 0")
output "Started a new game."
dialog:Hide()
end
end
The Yes button does not close the dialog on its own. Your behavior has
to call Hide, or the dialog stays open.
Now replace Main.quorum:
use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.Button
use Libraries.Interface.Controls.OptionDialog
use Libraries.Game.Graphics.Label
class Main is FormBehavior
OptionDialog question = undefined
Label score = undefined
action Main
Form form
Page page = form:GetMainPage()
score = page:AddLabel("Score", "Score: 50")
Button newGame = page:AddButton("New Game")
newGame:SetDescription("Asks before starting over")
newGame:SetBehavior(me)
form:Display()
end
action Run(BehaviorEvent event)
if question = undefined
OptionDialog dialog
dialog:SetLabelTitle("Start a new game?")
dialog:SetDescription("Yes sets your score to 0. No keeps playing.")
YesBehavior yesBehavior
yesBehavior:SetDialog(dialog)
yesBehavior:SetScoreLabel(score)
dialog:SetBehavior(yesBehavior)
question = dialog
end
question:Show()
end
end
Here is what is new:
Mainis the New Game button's behavior, as in the Forms tutorial. ItsRunaction opens the question.- The dialog is made inside
Run. An option dialog gets its drawing ready as soon as it is made, and that only works once the app's window is open.Runhappens when someone presses the button, which is always afterform:Display(). Theif question = undefinedcheck makes the dialog only the first time, and keeps it inquestionto reuse. SetLabelTitle("Start a new game?")sets the question. It also names the dialog "Start a new game? Dialog", which is shown in the top bar and read by a screen reader.SetDescriptionadds more detail for screen reader users, so they know what Yes and No will do.SetBehavior(yesBehavior)connects yourYesBehaviorto the Yes button.
Run the program and press New Game. Pick No, and the score stays at 50. Press New Game again and pick Yes, and the score goes to 0.
Doing something when the person picks No
By default, No only closes the dialog. If your program needs to do
something on No, write a behavior and give it to SetCancelBehavior. Add a
class named NoBehavior.quorum:
use Libraries.Interface.Behaviors.Behavior
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.OptionDialog
class NoBehavior is Behavior
OptionDialog dialog = undefined
action SetDialog(OptionDialog dialog)
me:dialog = dialog
end
action Run(BehaviorEvent event)
output "Kept playing."
dialog:Hide()
end
end
Then add these lines to Run in Main, right after
dialog:SetBehavior(yesBehavior):
NoBehavior noBehavior
noBehavior:SetDialog(dialog)
dialog:SetCancelBehavior(noBehavior)
Just like Yes, once you replace the No behavior, your behavior must call
Hide.
Using the keyboard
When the dialog opens, Quorum puts the focus on the Yes button. Here is what the keys do:
- Tab moves between Yes and No.
- Space or Enter presses the button that has the focus.
- Escape closes the dialog without running either behavior. Treat Escape the same as No: your program should not change anything.
When the dialog closes, the focus goes back to the New Game button.
Because the focus starts on Yes, a person who presses Enter right away picks Yes. That is fine for "Start a new game?", but think carefully before using an option dialog for something that can't be undone, like deleting a file.
When to use an option dialog
An option dialog is a good choice when:
- the question has two answers, yes or no;
- the action is hard to undo, like starting over or deleting;
- the person might have chosen the action by mistake.
It is a poor choice when the action is small or easy to undo. Asking too often teaches people to press Yes without reading. If you need different answers, more text, or other controls, build your own dialog with a page, as shown in the Dialogs tutorial.
Dialogs that trick people
People trust dialogs, because a dialog seems to come from the computer itself. Attackers use that trust. Tricking a person into doing something unsafe, such as paying, downloading a program or typing a password, is called social engineering. One kind uses fake warnings, called scareware: a message that claims your computer has a problem, so you will pay for a fix you don't need.
In 2008, the US Federal Trade Commission (FTC) took a group of companies to court for scareware. The FTC said that the companies placed ads that sent people to web sites claiming to scan their computers. The scans reported viruses, spyware and errors that weren't there, and urged people to buy security programs for $39.95 or more. The FTC said more than one million people were tricked. The ads also fooled the web sites that showed them, since the companies pretended to buy ad space for real businesses. A court ordered the companies to stop making the false claims (source).
Here is a made-up fake warning, written for this tutorial:
WARNING! 37 viruses found! Your files will be deleted in 60 seconds. Press Yes to fix your computer now.
Notice the tricks: a scary claim with an exact number, a countdown that rushes you, and a Yes button that only leads to a payment. An honest dialog does the opposite. It says exactly what will happen, it doesn't invent a deadline, it makes No as easy to pick as Yes, and its name matches the program that opened it. To protect yourself, don't trust a warning that appears inside a web page or an ad. Close it, and check with the security program that is really installed on your computer.
Engage
In this activity, you and a partner change an option dialog so it asks a
clear question before an action that can't be undone. The goal is to decide
when a program should ask first, and to write a question whose answer is
obvious. Start with the program above. Then pick an action from your Warm
up list that should ask first, and change the program so the button, the
question and the description all match that action. Change what
YesBehavior does to fit.
Have your partner use the program with only the keyboard, and ask them: did they know what Yes would do before they pressed it? Then rewrite the question so the answer is clear even without the description. For example, "Delete my_story.txt?" is clearer than "Are you sure?"
Next, each of you writes, on paper or with physical manipulatives, a made-up fake warning in the style of the scareware example, with at least two tricks in it. Swap them. Find every trick in your partner's warning, and rewrite it as an honest dialog. Then debate it together: in the FTC case, who was harmed, and how? Sort your answers into people, businesses, and governments, and agree on one way to prevent each harm.
Wrap up
An option dialog is a small speed bump. When does a speed bump protect people, and when does it only slow them down? Who should decide which actions get one: the programmer, or the person using the program? A fake warning and a real one can use the same dialog. What makes one honest?