How to resolve the algorithm GUI enabling/disabling of controls step by step in the J programming language
How to resolve the algorithm GUI enabling/disabling of controls step by step in the J programming language
Table of Contents
Problem Statement
In addition to fundamental GUI component interaction, an application should dynamically enable and disable GUI components, to give some guidance to the user, and prohibit (inter)actions which are inappropriate in the current state of the application.
Similar to the task GUI component interaction, write a program that presents a form with three components to the user:
The field is initialized to zero. The user may manually enter a new value into the field, 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 "increment" button only as long as the field's value is less then 10: When the value 10 is reached, the button should go into a disabled state. Analogously, the "decrement" button should be enabled only as long as the value is greater than zero. Effectively, the user can now either increment up to 10, or down to zero. Manually entering values outside that range is still legal, but the buttons should reflect that and enable/disable accordingly.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm GUI enabling/disabling of controls step by step in the J programming language
Source code in the j programming language
task_run=: wd bind (noun define)
pc task nosize;
cc decrement button;cn "Decrement";
cc increment button;cn "Increment";
cc Value edit center;set Value text 0;
set decrement enable 0;
pas 6 6;pcenter;
pshow;
)
task_cancel=: task_close=: wd bind 'pclose'
task_Value_button=: update=: verb define
wd 'set Value text ', ": n=. {. 0 ". Value
wd 'set Value enable ', ": n=0
wd 'set increment enable ', ": n<10
wd 'set decrement enable ', ": n>0
)
task_increment_button=:verb define
update Value=: ": 1 + 0 ". Value
)
task_decrement_button=:verb define
update Value=: ": _1 + 0 ". Value
)
task_run=: wd bind (noun define)
pc task nosize;
xywh 6 30 48 12;cc decrement button;cn "-";
xywh 6 18 48 12;cc increment button;cn "+";
xywh 6 6 48 12;cc Value edit; set Value 0;
pas 6 6;pcenter;
pshow;
)
task_close=: wd bind 'pclose'
task_Value_button=: update=: verb define
wd 'set Value ', ": n=. {. 0 ". Value
wd 'setenable Value ', ": n=0
wd 'setenable increment ', ": n<10
wd 'setenable decrement ', ": n>0
)
task_increment_button=:verb define
update Value=: ": 1 + 0 ". Value
)
task_decrement_button=:verb define
update Value=: ": _1 + 0 ". Value
)
task_run''
You may also check:How to resolve the algorithm Date format step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Loops/Break step by step in the D programming language
You may also check:How to resolve the algorithm String length step by step in the Zig programming language
You may also check:How to resolve the algorithm Terminal control/Inverse video step by step in the COBOL programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Insitux programming language