Lessons 45–46 · 2 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 10, 1st edition. “Extremum-Press”, Tashkent, 2017
46
Practical lesson
Textbook: pp. 101–102
GoalUses Visible and Enabled to build applications with several buttons and labels in which buttons switch each other on, off and hidden.
New words
state: the current condition of an object (visible, enabled) · holatswitching: changing the state from one to another · o‘tishtracing: writing the states after every click in a table · jadvalga yozishtest case: a planned sequence of clicks with an expected result · sinov holati
Explanation
In the practical lesson a “Traffic light” application is created: three texts (Labels) – RED, YELLOW, GREEN – and three buttons on the window. The buttons show the matching text and hide the other two, for example Label1.Visible := True; Label2.Visible := False; Label3.Visible := False; At the start none of the three texts is visible. In the second part build an application with two buttons and one label: the first button hides and shows the label (Label1.Visible := not Label1.Visible), and the second button makes the first button enabled or greyed out (Button1.Enabled := not Button1.Enabled). After starting, press a sequence of buttons, write the state after each click in a table and compare it with the table you calculated in advance. The traffic light is only a learning model: on a real road you must obey the signals.
Worked examples
A two-button application: when Button1 is pressed, Label1.Visible := not Label1.Visible; when Button2 is pressed, Button1.Enabled := not Button1.Enabled; At the start the label is visible and Button1 is enabled. The sequence: 1, 2, 1, 2, 1. The 1st click hides the label; the 2nd greys out Button1; the 3rd falls on the greyed button and nothing changes; the 4th enables Button1 again; the 5th shows the label. At the end the label is visible and Button1 is enabled.
Traffic light: after pressing “RED”, exactly 1 text is visible. If all three buttons are pressed one after another, exactly one text is visible each time, because the previous one is hidden. If the buttons did not hide the other two, all three texts would be visible after the third press.
Class activity
“The state table”: a group designs an 8-click sequence for the two-button application and calculates the state table; another group checks it in the application.
Practice
1
How many texts are visible in the traffic light after a button is pressed?
1
2
If Button2.Enabled := not Button2.Enabled; is run 5 times and Button2 was enabled at the start, what is the state?
Off (False)
3
Does a visible button with Enabled = False answer a click?
No, it is greyed out and cannot be pressed.
4
Why is it useful to disable a button the user does not need?
Wrong clicks are prevented and the user sees which action is possible.