Jump to content

GUI component interaction: Difference between revisions

m
→‎{{header|Haskell}}: made use of wxHaskell's 'when' function
(→‎{{header|Haskell}}: added Haskell solution)
m (→‎{{header|Haskell}}: made use of wxHaskell's 'when' function)
Line 625:
ran <- button frm [text := "random", on command := (randReplace fld frm)]
set frm [layout := margin 5 $ floatCentre $ column 2
[centre $ widget fld, row 2 [widget inc, widget ran]]]
 
increment :: Textual w => w -> IO ()
increment field = do
val <- get field text
ifwhen ((not . null) val) $ set field [text := show $ 1 + read val]
then set field [text := show $ 1 + read val]
else return ()
 
checkKeys :: EventKey -> IO ()
Line 642 ⟶ 640:
randReplace field frame = do
answer <- confirmDialog frame "Random" "Generate a random number?" True
thenwhen answer $ getStdRandom (randomR (1,100)) >>= \num ->
if answer
then set field [text := show $(num 1 + read:: valInt)]</lang>
then getStdRandom (randomR (1,100)) >>= \num ->
set field [text := show (num :: Int)]
else return ()</lang>
 
==Icon and {{header|Unicon}}==
8

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.