GUI enabling/disabling of controls: Difference between revisions
Content added Content deleted
m ({{out}} / -Category:Scala Implementations) |
|||
Line 1: | Line 1: | ||
{{task|GUI}}{{requires|Graphics}} |
{{task|GUI}} {{requires|Graphics}} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
In addition to fundamental [[GUI component interaction]], an application should |
In addition to fundamental [[GUI component interaction]], an application should |
||
dynamically enable and disable GUI components, to give some guidance to the |
dynamically enable and disable GUI components, to give some guidance to the |
||
Line 5: | Line 21: | ||
of the application. |
of the application. |
||
The task: Similar to the task [[GUI component interaction]] write a program |
The task: Similar to the task [[GUI component interaction]] write a program |
||
presents a form with three components to the user: |
that presents a form with three components to the user: |
||
("Value") and two buttons ("increment" and "decrement"). |
A numeric input field ("Value") and two buttons ("increment" and "decrement"). |
||
The field is initialized to zero. |
The field is initialized to zero. |
||
The user may manually enter a new value into the field, |
|||
the field, increment its value with the "increment" button, or decrement the |
|||
value with the " |
increment its value with the "increment" button, |
||
or decrement the value with the "decrement" button. |
|||
The input field should be enabled only when its value is zero. |
The input field should be enabled only when its value is zero. |
||
button only as long as the field's value is less then 10: |
The "increment" button only as long as the field's value is less then 10: |
||
reached, the button should go into a disabled state. |
When the value 10 is reached, the button should go into a disabled state. |
||
"decrement" button should be enabled only as long as |
Analogously, the "decrement" button should be enabled only as long as |
||
the value is greater than zero. |
|||
zero. |
|||
Effectively, the user can now either increment up to 10, or down to zero. |
Effectively, the user can now either increment up to 10, or down to zero. |
||
Manually entering values outside that range is still legal, |
Manually entering values outside that range is still legal, |
||
should reflect that and enable/disable accordingly. |
but the buttons should reflect that and enable/disable accordingly. |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
Line 283: | Line 300: | ||
SYS "SetDlgItemInt", !form%, 101, number% - 1, 1 |
SYS "SetDlgItemInt", !form%, 101, number% - 1, 1 |
||
ENDPROC</lang> |
ENDPROC</lang> |
||
{{out}} |
|||
Output: |
|||
<p> |
<p> |
||
[[File:Guienabbc.gif]] |
[[File:Guienabbc.gif]] |
||
Line 1,489: | Line 1,506: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
[[Category:Scala Implementations]] |
|||
<lang Scala>import swing.{ BoxPanel, Button, GridPanel, Orientation, Swing, TextField } |
<lang Scala>import swing.{ BoxPanel, Button, GridPanel, Orientation, Swing, TextField } |
||
import swing.event.{ ButtonClicked, Key, KeyPressed, KeyTyped } |
import swing.event.{ ButtonClicked, Key, KeyPressed, KeyTyped } |
||
Line 1,598: | Line 1,614: | ||
updateEnables; # Force initial state of buttons</lang> |
updateEnables; # Force initial state of buttons</lang> |
||
⚫ | |||
⚫ | |||
=={{header|Visual Basic}}== |
=={{header|Visual Basic}}== |
||
In VB, windows are usually created in the IDE. |
In VB, windows are usually created in the IDE. |
||
The generated code is hidden from the user unless viewed outside of VB. |
|||
For the sake of this task, I have included that code. |
|||
(Also, this sort of task would typically be performed |
(Also, this sort of task would typically be performed |
||
by a "spinner" or "up-down" control, not by buttons.) |
|||
<lang vb>VERSION 5.00 |
<lang vb>VERSION 5.00 |
||
Line 1,677: | Line 1,695: | ||
End Select |
End Select |
||
End Sub</lang> |
End Sub</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ |