Java Reference
In-Depth Information
Chapter 6
Conditional Logic and Checkboxes
In this chapter, we will tackle conditional logic. Conditional logic, also called “If Then Else” logic, is used extensively in
programming. It has probably been used in almost every “real-world” program ever written! We will use conditional
logic to enhance our applications so that frames can perform multiple functions and execute calculations that are
more realistic. (Conditional logic can be a little baffling to first-time programmers but I have confidence in you!)
In addition, we will cover some new GUI components, item events, and delve deeper into comparison operators.
Because our application logic will be getting much more complex, we will also begin working with the Debug
perspective to find and resolve errors in the source code.
In this chapter, you will learn about:
Comparisons
Conditional logic
Events
Checkboxes
Checkbox groups
Dispose versus System.exit
After this chapter, you should be able to:
Use an if/else statement
Use an ItemEvent
Check a component's state
Build compound conditions with ands and ors
Set breakpoints
Step through statements in the Debug perspective
Conditional Logic
The term “conditional logic” sounds imposing but the concept is very simple: a statement is performed only if a
condition is true. Another way to say it is: If condition is true then perform this action. You use conditional logic every
day. For instance, when you are driving: If traffic light is red then stop. Or said another way, the function stop is only
performed when the condition is true. Pretty simple, right?
Every high-level programming language provides commands to execute statements conditionally. Java uses the
keyword if and optionally the else keyword to perform conditional logic.
 
Search WWH ::




Custom Search