Anonymous user
GUI component interaction: Difference between revisions
m
→{{header|Elena}}
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
imported>Arakov |
||
(13 intermediate revisions by 7 users not shown) | |||
Line 13:
{{omit from|Lotus 123}}
{{omit from|Maxima}}
{{omit from|Minimal BASIC|It does not handle GUI}}
{{omit from|Nascom BASIC|It does not handle GUI}}
{{omit from|PARI/GP}}
{{omit from|PostScript}}
{{omit from|Retro}}
{{omit from|SQL PL|It does not handle GUI}}
{{omit from|Tiny BASIC|It does not handle GUI}}
{{omit from|Palo Alto Tiny BASIC|It does not handle GUI}}
Almost every application needs to communicate with the user in some way.
Line 51 ⟶ 54:
=={{header|1C}}==
<syntaxhighlight lang="text">
&НаСервере
Процедура ДобавитьЭлементы()
Line 110 ⟶ 113:
КонецПроцедуры
</syntaxhighlight>
=={{header|Ada}}==
Line 116 ⟶ 119:
interaction.adb:
<
with Ada.Strings.Fixed;
with Gtk.Main;
Line 273 ⟶ 276:
Gtk.Main.Main;
end Interaction;</
=={{header|AutoHotkey}}==
<
; Making our own check necessary. (MakeSure)
Line 330 ⟶ 333:
ExitApp ; Makes sure the script exits when the window is closed,
; Otherwise the script is persistent because it contains
; a timer.</
=={{header|
==={{header|BaCon}}===
Requires BaCon version 4.0.1 or higher, using GTK3.
<
PRAGMA GUI gtk3
Line 369 ⟶ 373:
CALL GUIFN(gui, "confirm", hide)
ENDSELECT
WEND</
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<
INSTALL @lib$+"WINLIB5"
Line 402 ⟶ 406:
SYS "MessageBox", !form%, "Set to a random value?", "Confirm", MB_YESNO TO reply%
IF reply% = IDYES THEN SYS "SetDlgItemInt", !form%, 101, RND(10000), 1
ENDPROC</
{{Out}}
<p>[[File:Guiintbbc.gif]]</p>
Line 411 ⟶ 415:
<pre>file main.c</pre>
<
#include "resource.h"
Line 458 ⟶ 462:
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPInst, LPSTR cmdLn, int show ) {
return DialogBox( hInst, MAKEINTRESOURCE(IDD_DLG), NULL, DlgProc );
}</
<pre>file resource.h</pre>
<
#define IDC_INPUT 1001
#define IDC_INCREMENT 1002
#define IDC_RANDOM 1003
#define IDC_QUIT 1004</
<pre>file resource.rc</pre>
<
#include "resource.h"
Line 483 ⟶ 487:
PUSHBUTTON "Random", IDC_RANDOM, 62, 25, 50, 14
PUSHBUTTON "Quit", IDC_QUIT, 117, 25, 30, 14
}</
=={{header|C++}}==
with library Qt 4.4 , using (under Linux) first qmake -project and then qmake -o Makefile <projectfile>, then make
<pre>file interaction.h</pre>
<
#define INTERACTION_H
#include <QWidget>
Line 509 ⟶ 513:
void findRandomNumber( ) ;
} ;
#endif</
<pre>file interaction.cpp</pre>
<
#include <QLineEdit>
#include <QMessageBox>
Line 558 ⟶ 562:
break ;
}
}</
<pre>file main.cpp </pre>
<
#include "interaction.h"
Line 568 ⟶ 572:
theWidget.show( ) ;
return app.exec( ) ;
}</
===C++11===
Line 575 ⟶ 579:
<pre>main.cpp</pre>
<
#include <QWidget>
#include <QVBoxLayout>
Line 620 ⟶ 624:
return app.exec();
}</
=={{header|C_sharp|C#}}==
C# 3.0 with Windows Forms; compile as csc -t:winexe Program.cs on MS.NET or as gmcs -t:winexe Program.cs on Mono.
<
using System.ComponentModel;
using System.Windows.Forms;
Line 697 ⟶ 701:
}
}
</syntaxhighlight>
=={{header|Common Lisp}}==
{{libheader|LTK}}
<
;; Using the LTK library...
Line 742 ⟶ 746:
(gui-test)
</syntaxhighlight>
=={{header|Delphi}}==
<syntaxhighlight lang
<syntaxhighlight lang="delphi">
unit Unit1;
Line 799 ⟶ 803:
end;
end.</
<
<syntaxhighlight lang="delphi">
object Form1: TForm1
Left = 1899
Line 845 ⟶ 849:
end
end
</syntaxhighlight>
=={{header|Echolisp}}==
<
(require 'interface)
Line 889 ⟶ 893:
(panel)
</syntaxhighlight>
=={{header|Elena}}==
ELENA
<
import extensions;
public class MainWindow : SDIDialog
{
}</
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
include GtkEngine.e -- see OpenEuphoria.org
Line 1,055 ⟶ 1,000:
end function
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
<
// GUI component interaction. Nigel Galloway: June 13th., 2020
let n=new System.Windows.Forms.Form(Size=new System.Drawing.Size(250,150))
Line 1,071 ⟶ 1,016:
l.Click.AddHandler(new System.EventHandler(fun _ _->i.Text<-(string(rand.Next()))))
System.Windows.Forms.Application.Run(n)
</syntaxhighlight>
=={{header|Fantom}}==
<
using fwt
using gfx
Line 1,140 ⟶ 1,085:
}
}
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
#Include "windows.bi"
Line 1,185 ⟶ 1,130:
End
</syntaxhighlight>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
_valLabel
_valFld
_incBtn
_rndBtn
end enum
_confirmAlert = 1
void local fn BuildWindow
window _window, @"GUI Components", (0,0,214,100), NSWindowStyleMaskTitled
textlabel _valLabel, @"Value:", (20,61,42,16)
textfield _valFld,, @"0", (68,59,126,21)
ControlSetFormat( _valFld, @"0123456789", YES, 3, 0 )
button _incBtn,,, @"Increment", (13,13,95,32)
button _rndBtn,,, @"Random", (106,13,95,32)
WindowMakeFirstResponder( _window, _valFld )
end fn
void local fn DoAppEvent( ev as long )
select ( ev )
case _appDidFinishLaunching
random
fn BuildWindow
end select
end fn
void local fn DoDialog( ev as long, tag as long )
select ( ev )
case _btnClick
select ( tag )
case _incBtn
long value = fn ControlIntegerValue( _valFld ) + 1
if ( value > 999 ) then value = 999
ControlSetStringValue( _valFld, fn StringWithFormat(@"%ld",value) )
case _rndBtn
long response = alert _confirmAlert,, @"Reset field", @"Do you want to reset the field to a random value?", @"OK;Cancel"
if ( response == NSAlertFirstButtonReturn )
ControlSetStringValue( _valFld, fn StringWithFormat(@"%ld",rnd(999)) )
end if
end select
end select
end fn
on appevent fn DoAppEvent
on dialog fn DoDialog
HandleEvents
</syntaxhighlight>
{{out}}
[[File:FB_GUIComponentInteraction.png]]
=={{header|Gambas}}==
<
Public Sub Form_Open()
Line 1,243 ⟶ 1,247:
End If
End</
=={{header|Go}}==
{{libheader|gotk3}}
{{trans|Vala}}
<
import (
Line 1,346 ⟶ 1,350:
window.ShowAll()
gtk.Main()
}</
=={{header|Haskell}}==
<
import System.Random
Line 1,375 ⟶ 1,379:
answer <- confirmDialog frame "Random" "Generate a random number?" True
when answer $ getStdRandom (randomR (1,100)) >>= \num ->
set field [text := show (num :: Int)]</
==Icon and {{header|Unicon}}==
Line 1,381 ⟶ 1,385:
This example uses the Unicon gui library, and so will not work in Icon.
<syntaxhighlight lang="unicon">
import gui
$include "guih.icn"
Line 1,489 ⟶ 1,493:
w.show_modal ()
end
</syntaxhighlight>
=={{header|J}}==
{{works with|J 8.x}}
<
pc interact;
cc Value edit center;
Line 1,523 ⟶ 1,527:
wd 'set Value text ' , ": ?100
end.
)</
{{works with|J 6.x}}
<
pc interact closeok;
xywh 6 6 48 12;cc Value edit;
Line 1,556 ⟶ 1,560:
wd 'set Value ' , ": ?100
end.
)</
Note: I used an edit box for the value, and edit boxes do not get onChange events, so rejection of non-numeric values will be delayed until the use of a button (or pressing enter).
Line 1,562 ⟶ 1,566:
Example use:
<syntaxhighlight lang
=={{header|Java}}==
Line 1,568 ⟶ 1,572:
{{works with|AWT}}
There are nice GUI editors in some IDEs (Netbeans has a notoriously good one), but this GUI was not built automatically, so it's a little easier to understand.
<
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Line 1,660 ⟶ 1,664:
new Interact().setVisible(true);
}
}</
{{works with|Java|8+}}
<
import java.awt.event.KeyListener;
Line 1,690 ⟶ 1,694:
public void keyReleased(KeyEvent event);
}
}</
<
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
Line 1,881 ⟶ 1,885:
;
}
}</
=={{header|Julia}}==
<
The task: For a minimal "application", write a program that
presents a form with three components to the user: A numeric input
Line 1,936 ⟶ 1,940:
while true sleep(1); end
</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
Line 1,991 ⟶ 1,995:
fun main(args : Array<String>) {
Interact().isVisible = true
}</
=={{header|Lambdatalk}}==
Line 1,997 ⟶ 2,001:
See http://lambdaway.free.fr/lambdawalks/?view=interaction
<
{input {@ id="input" type="text" value="0"}}
{input {@ type="button" value="increment"
Line 2,006 ⟶ 2,010:
document.getElementById('input').value =
Math.round(Math.random()*100);"}}
</syntaxhighlight>
=={{header|Liberty BASIC}}==
===Input Verification===
<
textbox #demo.val, 20, 50, 90, 24
button #demo.inc, "Increment", [btnIncrement], UL, 20, 90, 90, 24
Line 2,065 ⟶ 2,069:
#demo.val nVal
end if
wait</
===Impossible to type non-numeric characters===
<
stylebits #demo.val, _ES_NUMBER, 0, 0, 0
textbox #demo.val, 20, 50, 90, 24
Line 2,094 ⟶ 2,098:
#demo.val nVal
end if
wait</
=={{header|M2000 Interpreter}}==
Line 2,100 ⟶ 2,104:
Version 2, addition a title for form (without title, default title if form variable name, form1).
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Declare form1 form
Line 2,148 ⟶ 2,152:
}
Checkit
</syntaxhighlight>
=={{header|Maple}}==
For this problem, you will need to open up Maple, go to the Components tab on the left, and insert a Text Area, and 2 Buttons. By right clicking each button, and clicking Component Properties, change one to Increase, and the other to Random. Then, click on 'Edit Content Changed Action". In the one labeled increase, type:
<syntaxhighlight lang="maple">
Increase();
</syntaxhighlight>
In the one labeled Random, type:
<syntaxhighlight lang="maple">
Random();
</syntaxhighlight>
Then, by clicking the 2 gears and opening up the start-up commands, enter this:
<syntaxhighlight lang="maple">
macro(SP=DocumentTools:-SetProperty, GP=DocumentTools:-GetProperty);
with(Maplets[Elements]):
Line 2,179 ⟶ 2,183:
end if;
end proc;
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="text">Manipulate[Null, {{value, 0}, InputField[Dynamic[value], Number] &},
Row@{Button["increment", value++],
Button["random",
Line 2,189 ⟶ 2,193:
Row@{Button["Yes", DialogReturn[True]],
Button["No", DialogReturn[False]]}}],
value = RandomInteger@10000], Method -> "Queued"]}]</
=={{header|Nim}}==
===Gtk2===
{{libheader|Gtk2}}
<
gtk2, glib2, strutils, random
Line 2,253 ⟶ 2,257:
win.show_all()
main()</
===Gtk3 (gintro)===
{{libheader|gintro}}
This is a translation of the Gtk2 version to Gtk3 using the higher level "gintro" bindings. The higher level is not really obvious in this small example, but, for instance, we are able to transmit to signal handlers a pure Nim “Context” object (managed by the GC). With the Gtk2 bindings, it would require to use unsafe addresses.
<
import gintro/[glib, gobject, gtk, gio]
Line 2,352 ⟶ 2,356:
let app = newApplication(Application, "Rosetta.ComponentInteraction")
discard app.connect("activate", activate)
discard app.run()</
===IUP===
{{libheader|IUP}}
<
iup, strutils, math
Line 2,418 ⟶ 2,422:
discard dlg.show()
discard mainloop()
iup.close()</
=={{header|Oz}}==
Using Mozart's standard GUI library, building a small desktop application:
<
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']}
Line 2,463 ⟶ 2,467:
end
in
{Main}</
As a web application, using the "Roads" web programming library. Connect your browser to http://localhost:8080/start after starting the program.
<
[Roads] = {Module.link ['x-ozlib://wmeyer/roads/Roads.ozf']}
Line 2,521 ⟶ 2,525:
in
{Roads.registerFunction 'start' Start}
{Roads.run}</
=={{header|Perl}}==
<
use strict;
Line 2,550 ⟶ 2,554:
)->pack( -side => 'right' );
MainLoop;</
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/pGUI}}
<!--<
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 2,590 ⟶ 2,594:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PicoLisp}}==
The standard PicoLisp GUI is HTTP based. Connect your browser to
http://localhost:8080 after starting the following script.
<
(load "@ext.l" "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
Line 2,612 ⟶ 2,616:
(server 8080 "!start")
(wait)</
=={{header|PowerShell}}==
<
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Rosetta Code" WindowStartupLocation = "CenterScreen" Height="100" Width="210" ResizeMode="NoResize">
Line 2,639 ⟶ 2,643:
$buttonIncrement.add_click({++[Int]$textBoxValue.Text})
$XMLForm.ShowDialog() | Out-Null</
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
<
[ object :=
GUI_Interaction,
Line 2,724 ⟶ 2,728:
( send(@display, inform, 'Please type a number !'),
send(Input,clear))).
</syntaxhighlight>
=={{header|PureBasic}}==
<
#StringGadget
#Increment
Line 2,754 ⟶ 2,758:
Until Event=#PB_Event_CloseWindow
CloseWindow(0)
EndIf</
=={{header|Python}}==
Line 2,761 ⟶ 2,765:
{{libheader|Tkinter}}
{{works with|Python|2.7}}
<
import random, tkMessageBox
from Tkinter import *
Line 2,785 ⟶ 2,789:
b2 = Button(text="Random", command=rand, **options)
b2.grid(column=2, row=0, **options)
mainloop()</
===Python3 - no classes===
{{libheader|Tkinter}}
{{works with|Python|3.7}}
<
import random, tkinter.messagebox
from tkinter import *
Line 2,819 ⟶ 2,823:
b2.grid(column=2, row=0, **options)
mainloop()</
===Python2 - With classes===
{{libheader|Tkinter}}
<
from Tkinter import *
import tkMessageBox
Line 2,875 ⟶ 2,879:
app.mainloop()
except KeyboardInterrupt:
root.destroy()</
[[File:GUI_component_interaction_Python.png]]
=={{header|R}}==
<syntaxhighlight lang="r">
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
Line 2,911 ⟶ 2,915:
svalue(e) <- sample(1:1000, 1)
})
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket/gui
Line 2,940 ⟶ 2,944:
(send frame show #t)
</syntaxhighlight>
=={{header|Raku}}==
Line 2,947 ⟶ 2,951:
{{libheader|GTK}}
<syntaxhighlight lang="raku"
use GTK::Simple::App;
Line 2,980 ⟶ 2,984:
}
$app.run;</
=={{header|Ring}}==
<
Load "guilib.ring"
Line 3,015 ⟶ 3,019:
num = string(number(num)+1)
lineedit1.settext(num)
</syntaxhighlight>
Output:
Line 3,023 ⟶ 3,027:
=={{header|Ruby}}==
{{libheader|Shoes}}
<
stack do
textbox = edit_line
Line 3,041 ⟶ 3,045:
end
end
end</
=={{header|Run BASIC}}==
<
for i = 1 to 5
dd$(i) = "Drop ";i
Line 3,086 ⟶ 3,090:
[exit]
print "Bye"
end</
[[File:GuiComponentRunBasic.png]]
== {{Header|Rust}} ==
{{libheader|egui}}
<syntaxhighlight lang="rust">
use eframe::egui;
use rand::Rng;
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(214.0, 100.0)),
..Default::default()
};
// Our application state:
let mut value = "0".to_owned();
eframe::run_simple_native("GUI component interaction", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.horizontal(|ui| {
let name_label = ui.label("Value: ");
ui.text_edit_singleline(&mut value)
.labelled_by(name_label.id);
});
ui.horizontal(|ui| {
if ui.button("Increment").clicked() {
if let Ok(v) = value.parse::<usize>() {
value = (v + 1).to_string()
}
}
if ui.button("Random").clicked() {
value = (rand::thread_rng().gen_range(1..=10000)).to_string();
}
});
});
})
}</syntaxhighlight>
[[File:Rust GUI component interaction.png|none|thumb]]
=={{header|Scala}}==
<
import scala.swing.Swing._
import scala.swing.event._
Line 3,134 ⟶ 3,175:
centerOnScreen()
}
}</
=={{header|Smalltalk}}==
{{works with|Smalltalk/X}}
<
vh := ValueHolder with:0.
Line 3,155 ⟶ 3,196:
rndButton action:[ vh value: Random nextInteger ].
top open</
{{Out}}
[[File:Guiintsmalltalkx.png]]
Line 3,161 ⟶ 3,202:
=={{header|Tcl}}==
{{libheader|Tk}}
<
###--- Our data Model! ---###
Line 3,195 ⟶ 3,236:
set field [expr {int(rand() * 5000)}]
}
}</
=={{header|Vala}}==
{{libheader|Gtk+-3.0}}
<
int64 val;
bool ret = int64.try_parse(str,out val);;
Line 3,281 ⟶ 3,322:
return 0;
}
</syntaxhighlight>
=={{header|Visual Basic}}==
Line 3,289 ⟶ 3,330:
Note that there are other methods of validating the entered value. The method used is dependant on the program's requirements.
<
Begin VB.Form Form1
Caption = "Form1"
Line 3,350 ⟶ 3,391:
KeyAscii = 0
End Select
End Sub</
=={{header|V (Vlang)}}==
Graphical
Notes:
1) "v install ui" to get, also to locally check source and examples.
2) For alternative UI toolkits, check github.com/vlang/awesome-v (Awesome V).
<syntaxhighlight lang="Zig">
import ui
import gx
import rand
const (
win_width = 400
win_height = 40
)
[heap]
struct App {
mut:
window &ui.Window = unsafe {nil}
counter string = "0"
}
fn main() {
mut app := &App{}
app.window = ui.window(
width: win_width
height: win_height
title: "Counter"
mode: .resizable
layout: ui.row(
spacing: 5
margin_: 10
widths: ui.stretch
heights: ui.stretch
children: [
ui.textbox(
max_len: 20
read_only: false
// is_numeric: true // Can enforce only number input
text: &app.counter
),
ui.button(
text: "increment"
bg_color: gx.light_gray
radius: 5
border_color: gx.gray
on_click: app.btn_click_inc
),
ui.button(
text: "random"
bg_color: gx.light_gray
radius: 5
border_color: gx.gray
on_click: app.btn_click_ran
),
]
)
)
ui.run(app.window)
}
fn (mut app App) btn_click_inc(mut btn ui.Button) {
for value in app.counter {
if value.is_digit() == false {
ui.message_box("Only numbers allowed!")
return
}
}
if app.counter.int() < 0 || app.counter.int() > 100 {
ui.message_box("Only numbers between 0 to 100 accepted!\nResetting to 1.")
app.counter = "0"
}
app.counter = (app.counter.int() + 1).str()
}
fn (mut app App) btn_click_ran(mut btn ui.Button) {
ui.message_box("Will jump to random number between 1 and 100.")
app.counter = rand.int_in_range(1, 100) or {0}.str()
}
</syntaxhighlight>
=={{header|Web 68}}==
Web 68 uses an include file to use the Xforms library.
<
@aPROGRAM guicomponent CONTEXT VOID USE standard
BEGIN
Line 3,483 ⟶ 3,608:
macro fl show form;
@ The end.</
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|Wren-polygon}}
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
import "input" for Mouse, Keyboard
import "dome" for Window
import "random" for Random
import "./polygon" for Polygon
var Rand = Random.new()
class Button {
construct new(x, y, w, h, legend, c, oc, lc) {
var vertices = [[x, y], [x+w, y], [x+w, y+h], [x, y+h]]
_rect = Polygon.quick(vertices)
_x = x
_y = y
_w = w
_h = h
_legend = legend
_c = c
_oc = oc
_lc = lc
}
draw() {
_rect.drawfill(_c)
_rect.draw(_oc)
var l = Canvas.getPrintArea(_legend)
var lx = ((_w - l.x)/2).truncate
lx = (lx > 0) ? _x + lx : _x + 1
var ly = ((_h - l.y)/2).truncate
ly = (ly > 0) ? _y + ly : _y + 1
Canvas.print(_legend, lx, ly, _lc)
}
justClicked { Mouse["left"].justPressed && _rect.contains(Mouse.position.x, Mouse.position.y) }
}
class TextBox {
construct new(x, y, w, h, label, c, oc, lc) {
var vertices = [[x, y], [x+w, y], [x+w, y+h], [x, y+h]]
_rect = Polygon.quick(vertices)
_x = x
_y = y
_w = w
_h = h
_label = label
_c = c
_oc = oc
_lc = lc
_text = ""
}
text { _text }
text=(t) { _text = t }
draw() {
_rect.drawfill(_c)
_rect.draw(_oc)
var l = Canvas.getPrintArea(_label).x
var lx = _x - l - 7
if (lx < 1) {
lx = 1
_label = _label[0..._x]
}
Canvas.print(_label, lx, _y, _lc)
Canvas.getPrintArea(_label).x
Canvas.print(_text, _x + 3, _y + 1, Color.black)
}
}
class GUIComponentInteraction {
construct new() {
Window.title = "GUI component interaction"
_btnIncrement = Button.new(60, 40, 80, 80, "Increment", Color.red, Color.blue, Color.white)
_btnRandom = Button.new(180, 40, 80, 80, "Random", Color.green, Color.blue, Color.white)
_txtValue = TextBox.new(140, 160, 80, 8, "Value", Color.white, Color.blue, Color.white)
_txtValue.text = "0"
Keyboard.handleText = true
_waiting = false
}
init() {
drawControls()
}
update() {
if (_waiting) {
if (Keyboard["Y"].justPressed) {
var rn = Rand.int(1000) // max 999 say
_txtValue.text = rn.toString
_waiting = false
} else if (Keyboard["N"].justPressed) {
_waiting = false
}
} else if (_btnIncrement.justClicked) {
var number = Num.fromString(_txtValue.text) + 1
_txtValue.text = number.toString
} else if (_btnRandom.justClicked) {
Canvas.print("Reset to a random number y/n?", 60, 200, Color.white)
_waiting = true
} else if ("0123456789".any { |d| Keyboard[d].justPressed }) {
if (_txtValue.text != "0") {
_txtValue.text = _txtValue.text + Keyboard.text
} else {
_txtValue.text = Keyboard.text
}
}
}
draw(alpha) {
if (!_waiting) drawControls()
}
drawControls() {
Canvas.cls()
_btnIncrement.draw()
_btnRandom.draw()
_txtValue.draw()
}
}
var Game = GUIComponentInteraction.new()</syntaxhighlight>
|