GUI component interaction: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: added Haskell solution)
m (→‎{{header|Haskell}}: made use of wxHaskell's 'when' function)
Line 625: Line 625:
ran <- button frm [text := "random", on command := (randReplace fld frm)]
ran <- button frm [text := "random", on command := (randReplace fld frm)]
set frm [layout := margin 5 $ floatCentre $ column 2
set frm [layout := margin 5 $ floatCentre $ column 2
[centre $ widget fld, row 2 [widget inc, widget ran]]]
[centre $ widget fld, row 2 [widget inc, widget ran]]]


increment :: Textual w => w -> IO ()
increment :: Textual w => w -> IO ()
increment field = do
increment field = do
val <- get field text
val <- get field text
if (not . null) val
when ((not . null) val) $ set field [text := show $ 1 + read val]
then set field [text := show $ 1 + read val]
else return ()


checkKeys :: EventKey -> IO ()
checkKeys :: EventKey -> IO ()
Line 642: Line 640:
randReplace field frame = do
randReplace field frame = do
answer <- confirmDialog frame "Random" "Generate a random number?" True
answer <- confirmDialog frame "Random" "Generate a random number?" True
when answer $ getStdRandom (randomR (1,100)) >>= \num ->
if answer
set field [text := show (num :: Int)]</lang>
then getStdRandom (randomR (1,100)) >>= \num ->
set field [text := show (num :: Int)]
else return ()</lang>


==Icon and {{header|Unicon}}==
==Icon and {{header|Unicon}}==