!7 module ShowRandomColor > DynSCP { RGB color; S myGuess, yourName; transient JTextField tfYourName; visualize2 { if (color == null) setField(color := randomColor()); JComponent theForm = withRightMargin(makeForm2( "I call this color:", dm_fieldLabel('myGuess), "How do you call this color?", centerAndEastWithMargin( onEnter(tfYourName = dm_fieldTextField('yourName), rThread saveName), jbutton("Save", rThread saveName)))); ret withRightAlignedButtons( centerAndSouthWithMargin( northAndCenterWithMargins( jRightAlignedLiveValueLabel(mapLiveValue(func(O color) -> S { "Color Code: #" + color }, S, dm_fieldLiveValue('color))), jSection("THE COLOR", singleColorPanel(toColor(color)))), jPreferredSizeToMinSizePlusY(5, theForm)), "New Color", rThread newColor); } void newColor enter { setField(color := randomColor()); setField(myGuess := or((S) dm_callModule(dm_colorNamesModule(), 'getClosestColorName, color.getColor()), "no idea")); revisualize2(); focusLater(tfYourName); } void saveName enter { dm_callModule(dm_colorNamesModule(), 'addColorName, color.getColor(), yourName, ""); newColor(); } }