Simple windowed application: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(Added reference to library.) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(53 intermediate revisions by 21 users not shown) | |||
Line 11:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program simpleWin64.s link with X11 library */
Line 457:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|Ada}}==
Line 466:
Apart from GtkAda, there exist numerous other GUI bindings and libraries:
CLAW, AdaGLUT, GWindow, JEWL, win32ada, QtAda etc.
<
with Gtk.Button; use Gtk.Button;
with Gtk.Label; use Gtk.Label;
Line 532:
Gtk.Main.Main;
end Simple_Windowed_Application;</
=={{header|APL}}==
{{works with|Dyalog APL}}
<
⍝ define a form with a label and a button
Line 553:
}
∇</
{{works with|GNU APL}}
[my-application.apl]
<syntaxhighlight lang="apl">#!/usr/local/bin/apl --script --OFF
⍝ Some GTK API consts for readability
⍝ event poll type for X ← ⎕gtk
Blocking ← 1
Nonblocking ← 2
∇Z←get_NAME_and_POSITION;GUI_path;CSS_path;Handle
GUI_path ← '/home/me/GNUAPL/workspaces/my-application.glade'
CSS_path ← '/home/me/GNUAPL/workspaces/my-application.css'
Handle ← CSS_path ⎕GTK GUI_path
⍝H_ID ← Handle, 'entry1' ⍝ Position field
⍝'<enter name>' ⎕gtk[H_ID] "set_text" ⍝ pre-fill entry
⊣⎕gtk Blocking ⍝ Wait for click event
Z ← ⊂1↓⎕gtk[Handle, 'entry1'] "get_text"
Z ← Z,⊂1↓⎕gtk[Handle, 'entry2'] "get_text"
⊣Handle ⎕gtk 0
∇
⍝ Launch GUI application
get_NAME_and_POSITION
</syntaxhighlight>
[my-application.css]
<syntaxhighlight lang="css">/* general button */
.BUTTON { color: #F00; background: #4F4; }
/* the OK button */
#OK-button { color: #A22; background: #FFF; }
</syntaxhighlight>
[my-application.glade]
<syntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_homogeneous">True</property>
<child>
<object class="GtkLabel" id="label1">
<property name="name">lblEmployee</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Employee</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="name">lblPosition</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Position</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="name">entryEmployee</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">1</property>
<property name="width">6</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="name">entryPosition</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">2</property>
<property name="width">6</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnOK">
<property name="label" translatable="yes">button</property>
<property name="name">OK-button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="clicked" swapped="no"/>
<style>
<class name="BUTTON"/>
</style>
</object>
<packing>
<property name="left_attach">4</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
</syntaxhighlight>
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">
set counter to 0
set dialogReply to display dialog ¬
"There have been no clicks yet" buttons {"Click Me", "Quit"} ¬
with title "Simple Window Application"
set theAnswer to button returned of the result
if theAnswer is "Quit" then quit
repeat
set counter to counter + 1
set dialogReply to display dialog counter buttons {"Click Me", "Quit"} ¬
with title "Simple Window Application"
set theAnswer to button returned of the result
if theAnswer is "Quit" then exit repeat
end repeat
</syntaxhighlight>
===Description===
AppleScript is the MacOS system automation language which creates scripts in various forms, including double-clickable applications, scripted folder actions, inner and inter application control and services, and more.
[https://www.melellington.com/simplewindow/Applescript-SWA.jpg Applescript Output]
=={{header|AutoHotkey}}==
<
Gui, Add, Text, vTextCtl, There have been no clicks yet ; add a Text-Control
Gui, Add, Button, gButtonClick xm, click me ; add a Button-Control
Line 569 ⟶ 719:
GuiClose: ; the subroutine executed when the Window is closed
ExitApp ; exit this process
Return</
=={{header|AutoIt}}==
<syntaxhighlight lang="autoit">
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
Line 597 ⟶ 747:
EndSwitch
WEnd
</syntaxhighlight>
=={{header|B4J}}==
<
#Region Project Attributes
#MainFormWidth: 593
Line 633 ⟶ 783:
Return falseVal
End If
End Sub</
Layout1.fxml (as B4J uses JavaFX's Scene Builder)
<
<?xml version="1.0" encoding="UTF-8"?>
Line 664 ⟶ 814:
</children>
</AnchorPane>
</syntaxhighlight>
=={{header|
==={{header|BaCon}}===
Requires BaCon version 4.0.1 or higher, using GTK3.
<
PRAGMA GUI gtk3
Line 685 ⟶ 836:
CALL GUISET(gui, "label", "label", "Button clicks: " & STR$(clicked))
ENDSELECT
WEND</
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<
INSTALL @lib$+"WINLIB5"
Line 706 ⟶ 857:
clicks% += 1
SYS "SetDlgItemText", !window%, 100, "Number of clicks = " + STR$(clicks%)
ENDPROC</
=={{header|Beads}}==
<
var g : record // global tracked mutable state
Line 751 ⟶ 902:
// update our click count
inc g.nclicks
g.label = to_str(g.nclicks)</
=={{header|C}}==
{{libheader|GTK}}
<
#include <gtk/gtk.h>
Line 794 ⟶ 945:
gtk_main();
return 0;
}</
=={{header|C sharp|C#}}==
<
class RosettaForm : Form
Line 827 ⟶ 978:
}
}
</syntaxhighlight>
=={{header|C++}}==
Line 833 ⟶ 984:
{{libheader|Qt}} 4.4 with source files as shown , built from a Makefile generated by the Qt tool qmake
===clickcounter.h===
<
#define CLICKCOUNTER_H
Line 853 ⟶ 1,004:
void countClicks( ) ;
} ;
#endif</
===clickcounter.cpp===
<
#include <QLabel>
#include <QVBoxLayout>
Line 874 ⟶ 1,025:
number++ ;
countLabel->setText( QString( "The button has been clicked %1 times!").arg( number ) ) ;
}</
===main.cpp===
<
#include "clickcounter.h"
Line 884 ⟶ 1,035:
counter.show( ) ;
return app.exec( ) ;
}</
=={{header|Clojure}}==
<
(:import (javax.swing JFrame JLabel JButton)))
Line 911 ⟶ 1,062:
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
(.setVisible true))))
</syntaxhighlight>
=={{header|Common Lisp}}==
Line 919 ⟶ 1,070:
{{works with|McCLIM}}
<
(:use #:clim #:clim-lisp))
(in-package #:rcswa)</
This version uses CLIM's command system:
<
((clicks :initform 0
:accessor clicks-of))
Line 943 ⟶ 1,094:
(define-simple-windowed-application-command (com-click-me :menu t)
()
(incf (clicks-of *application-frame*)))</
This version uses an explicit pushbutton gadget, and may be used if more direct control over the UI layout and behavior is needed:
<
((clicks :initform 0
:accessor clicks-of))
Line 973 ⟶ 1,124:
(vertically (:equalize-width nil :align-x :center)
the-label
(spacing (:thickness 10) the-button)))))</
In either case, the window is opened with:
<
=={{header|D}}==
Line 983 ⟶ 1,134:
{{works with|D|1}}
{{libheader|DFL}}
<
import dfl.all ;
import std.string ;
Line 1,013 ⟶ 1,164:
void main() {
Application.run(new MainForm);
}</
===Hybrid===
Line 1,035 ⟶ 1,186:
}
SimpleWindow.d:
<
import tango.text.convert.Integer;
import tango.core.Thread; // For Thread.yield
Line 1,070 ⟶ 1,221:
Thread.yield();
}
}</
=={{header|Delphi}}==
Line 1,080 ⟶ 1,231:
'''NOTE:''' The project name here must match the name of the file.
<
Program SingleWinApp ;
Line 1,166 ⟶ 1,317:
Application.Run ;
end. // Program</
=={{header|E}}==
{{libheader|Swing}}
{{works with|E-on-Java}}
<
var clicks := 0
def w := <swing:makeJFrame>("Rosetta Code 'Simple Windowed Application'")
Line 1,186 ⟶ 1,337:
w.pack()
w.show()
}</
=={{header|EchoLisp}}==
UI elements are HTML DOM Nodes. '''ui-add''' adds an element to the UI. '''ui-on-event''' adds a (Lisp) event handler to an element.
<
(define (ui-add-button text) ;; helper
(define b (ui-create-element "button" '((type "button"))))
Line 1,213 ⟶ 1,364:
(panel)
</syntaxhighlight>
=={{header|Elena}}==
ELENA
<
import extensions;
Line 1,229 ⟶ 1,380:
constructor new()
<= super new()
{
lblClicks := Label.new();
Line 1,257 ⟶ 1,408:
lblClicks.Caption := "Clicks: " + clicksCount.toString();
}
}</
=={{header|Euphoria}}==
===EuWinGUI===
{{libheader|EuWinGUI}}
<
Window("EuWinGUI - Simple windowed application",100,100,360,100)
Line 1,280 ⟶ 1,431:
end while
CloseApp(0)</
=={{header|F_Sharp|F#}}==
{{trans|C#}}
<
let mutable clickCount = 0
Line 1,299 ⟶ 1,450:
form.Controls.Add(button)
Application.Run(form)</
=={{header|Factor}}==
<
sequences ui ui.gadgets ui.gadgets.borders ui.gadgets.buttons
ui.gadgets.grids ui.gadgets.labels ui.gadgets.worlds ;
Line 1,328 ⟶ 1,479:
: main ( -- ) 1 n set build-ui ;
MAIN: main</
=={{header|Fantom}}==
<
using fwt
using gfx
Line 1,362 ⟶ 1,513:
}
}
</syntaxhighlight>
=={{header|Forth}}==
===with MINOS===
{{works with|bigFORTH}}
{{libheader|MINOS}}
<
text-label ptr click-label
Variable click# click# off
Line 1,377 ⟶ 1,529:
click-label assign ]S X" Click me" button new
&2 vabox new panel s" Clicks" assign show endwith ;
click-win</
===The same with Theseus===
{{works with|bigFORTH}}
{{libheader|Theseus}}
<
\ automatic generated code
\ do not edit
Line 1,416 ⟶ 1,569:
$1 0 ?DO stop LOOP bye ;
script? [IF] main [THEN]
previous previous previous</
===with Tk/wish===
{{works with|gforth|0.7.3}}
{{libheader|Tk}}
Creates a GUI with 'wish' from tk library. Uses pipes on standard input and output (created throw linux system calls).
<syntaxhighlight lang="forth">0 value tk-in
0 value tk-out
variable #clicks
0 #clicks !
: wish{ \ send command to wish
tk-in to outfile-id ;
: }wish \ finish command to wish
tk-in flush-file throw
stdout to outfile-id ;
: add-one 1 #clicks +! ;
: update-wish wish{ .\" .label configure -text \"clicks: " #clicks @ . .\" \"" cr }wish ;
: counting
begin
tk-out key-file
dup '+' = if add-one update-wish then \ add one if '+' received
4 = until ; \ until Ctrl-D, wish exit
: initiating
s" mkfifo tk-in tk-out" system
s" wish <tk-in >tk-out &" system
s" tk-in" w/o open-file throw to tk-in
s" tk-out" r/o open-file throw to tk-out
wish{ .\" pack [ label .label -text \"There have been no clicks yet\" ] " cr }wish
wish{ .\" pack [ button .click -text \"Click Me\" -command { puts \"+\" } ] " cr }wish ;
: cleaning
tk-in close-file
tk-out close-file
s" rm tk-in tk-out" system ;
initiating counting cleaning</syntaxhighlight>
===with iMops===
{{works with|iMops|2.23}}
Macintosh only - Uses native MacOS GUI calls to Cocoa.
<syntaxhighlight lang="forth">
:class TextView' super{ TextView }
:m put: ( addr len -- )
0 #ofChars: self SetSelect: self
insert: self ;m
;class
Window+ w
View wview
Button b
100 30 100 20 setFrame: b
TextView' t
200 30 200 15 setFrame: t
\ the running count is always on the stack
\ so a variable for that is not needed
:noname
1+ \ increment the count
" Number of clicks: " put: t
dup deciNumstr insert: t ; setAction: b \ update the text representation of count
: go
b addview: wview
t addview: wview
300 30 430 230 put: frameRect
frameRect " Test" docWindow
wview new: w show: w
" click me" setTitle: b
" There have been no clicks yet" put: t
0 ; \ the number of clicks start at zero
go</syntaxhighlight>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
#Include "windows.bi"
Line 1,454 ⟶ 1,685:
End
</syntaxhighlight>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">_window = 1
begin enum 1
_label
_clickMeBtn
end enum
void local fn BuildWindow
window _window, @"Simple Windowed Application", (0,0,366,59)
textlabel _label, @"There have been no clicks yet", (18,23,250,16)
button _clickMeBtn,,, @"Click Me", (267,13,86,32)
end fn
void local fn ButtonClicked
static long clickCount = 0
clickCount++
textlabel _label, fn StringWithFormat( @"The button has been clicked %ld times", clickCount )
end fn
void local fn DoDialog( ev as long, tag as long )
select ( ev )
case _btnClick
select ( tag )
case _clickMeBtn : fn ButtonClicked
end select
end select
end fn
fn BuildWindow
on dialog fn DoDialog
HandleEvents</syntaxhighlight>
=={{header|Gambas}}==
<
hLabel As Label 'We need a Label
Line 1,493 ⟶ 1,762:
hLabel.text = "The button has been clicked " & iCount & " times" 'Display the amount of clicks"
End</
=={{header|Gastona}}==
<
<frames> main, Simple click counter
Line 1,515 ⟶ 1,784:
-->, lClicks data!,, //@<NN> clicks so far
</syntaxhighlight>
=={{header|Go}}==
{{libheader|go-gtk}}
<
import (
Line 1,551 ⟶ 1,820:
window.ShowAll()
gtk.Main()
}</
=={{header|Groovy}}==
<
count = 0
Line 1,564 ⟶ 1,833:
}
}
}</
'''with binding:'''
<
import groovy.beans.Bindable
Line 1,582 ⟶ 1,851:
}
}
}</
=={{header|Guish}}==
<syntaxhighlight>
c=0
p=|p|;v
l=|l|;<"There have been no clicks yet"o
b=|b|;=>c{
c = add(1, @c)
@l<@c
}<"click me"
@p<<<@b<<<@l
@l w
@p,o+
</syntaxhighlight>
=={{header|Haskell}}==
{{libheader|Gtk}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<
import Data.IORef
Line 1,615 ⟶ 1,898:
widgetShowAll window
mainGUI</
=={{header|HicEst}}==
<
DO count = 1, 1E100 ! "forever"
Line 1,625 ⟶ 1,908:
ENDDO
END</
==Icon and {{header|Unicon}}==
This version is Unicon-specific:
<
$include "guih.icn"
Line 1,660 ⟶ 1,943:
initially
self.Dialog.initially()
end</
=={{header|IDL}}==
<
widget_control, ev.top, get_uvalue=tst
tst[1] = tst[1]+1
Line 1,676 ⟶ 1,959:
xmanager, "Simple", Id
end</
=={{header|J}}==
'''J 9.x''' (note: the J 8.x version works fine under J 9.x)<syntaxhighlight lang="j">simple_run=: {{
simple_clicks=: 0 NB. initialize accumulator
wd {{)n
pc simple closeok escclose;
cc click button;cn "Click me";
cc message static;cn "There have been no clicks yet.";
pshow;
}}}}
simple_run''
simple_click_button=: {{wd 'set message text Button-use count: ',": simple_clicks=: 1+simple_clicks}}</syntaxhighlight>
'''J 8.x'''
<
pc simpleApp;
cc inc button;cn "Click me";
Line 1,699 ⟶ 1,993:
simpleApp_cancel=: simpleApp_close
simpleApp_run''</
'''J 6.x'''
<
pc simpleApp;
xywh 131 11 44 12;cc inc button;cn "Click me";
Line 1,723 ⟶ 2,017:
simpleApp_cancel=: simpleApp_close
simpleApp_run''</
=={{header|Java}}==
{{libheader|AWT}}
{{libheader|Swing}}
<
import java.awt.Dimension;
import java.awt.event.ActionEvent;
Line 1,765 ⟶ 2,059:
);
}
}</
=={{header|JavaFX Script}}==
{{libheader|JavaFX 1.2}}
<
import javafx.scene.*;
import javafx.scene.layout.*;
Line 1,793 ⟶ 2,087:
}
}
}</
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">
<html>
<head>
<title>Simple Window Application</title>
</head>
<body>
<br>        
<script type="text/javascript">
var box = document.createElement('input')
box.style.position = 'absolute'; // position it
box.style.left = '10px';
box.style.top = '60px';
document.body.appendChild(box).style.border="3px solid white";
document.body.appendChild(box).value = "There have been no clicks yet";
document.body.appendChild(box).style['width'] = '220px';
var clicks = 0;
function count_clicks() {
document.body.appendChild(box).remove()
clicks += 1;
document.getElementById("clicks").innerHTML = clicks;
};
</script>
<button type="button" onclick="count_clicks()"> Click me</button>
<pre><p> Clicks: <a id="clicks">0</a> </p></pre>
</body>
</html>
</syntaxhighlight>
[http://melellington.com/simplewindow/javascript-simple-window.html Javascript Output]
----
=={{header|Julia}}==
Uses the Gtk library.
<syntaxhighlight lang="julia">using Gtk.ShortNames
function clickwindow()
Line 1,808 ⟶ 2,137:
push!(vbox, lab)
push!(vbox, but)
callback(w) = (clicks += 1;
id = signal_connect(callback, but,
Gtk.showall(win)
c = Condition()
endit(w) = notify(c)
signal_connect(endit, win, :destroy)
wait(c)
end
clickwindow()
</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.awt.BorderLayout
Line 1,862 ⟶ 2,190:
fun main(args: Array<String>) {
Clicks() // call the constructor where all the magic happens
}</
{{libheader|TornadoFX}}
<
import tornadofx.*
Line 1,879 ⟶ 2,207:
fun main(args: Array<String>) = launch<ClicksApp>(args)
</syntaxhighlight>
=={{header|Lambdatalk}}==
Line 1,885 ⟶ 2,213:
The code is tested in this page: http://epsilonwiki.free.fr/lambdaway/?view=popup
<syntaxhighlight lang="scheme">
1) the label: {div {@ id="label"} There have been no clicks yet }
2) the button: {input {@ type="button" value="click me" onclick="CLICKAPP.inc()" }}
Line 1,899 ⟶ 2,227:
return {inc:inc}
})();
</syntaxhighlight>
=={{header|Liberty BASIC}}==
<
button #demo.btn, "Click Me", [btnClick], UL, 20, 50
statictext #demo.num, "There have been no clicks yet.", 20, 100, 240, 30
Line 1,917 ⟶ 2,245:
nClicks = nClicks + 1
#demo.num "The button has been clicked ";nClicks;" times."
wait</
=={{header|Lingo}}==
The standard approach in Lingo for creating GUIs and assigning scripts for handling user interaction is to use the graphical IDE/GUI-Builder "Director". But windows and sprites (visual elements) can also be created and scripted programmatically only:
<
-- window settings
Line 1,967 ⟶ 2,295:
_movie.stage.visible = 1
end</
=={{header|LiveCode}}==
The LiveCode script here meets the specification 100%,
but is not in common LiveCode style. Typically the
mouseUp command would be attached to the button
rather than to the 'card' (window). Nevertheless, the card
is in the object's message path so the button works well.
<syntaxhighlight lang="livecode">global count
on openCard
put empty into count
put "There have been no clicks yet" into field "clicks"
end openCard
on mouseUp
add 1 to count
put count into field "clicks"
end mouseUp</syntaxhighlight>
[http://melellington.com/simplewindow/livecode-simple-window.jpg LiveCode Output]
----
=={{header|Logo}}==
Line 1,973 ⟶ 2,326:
{{works with|MSWlogo}}
<
windowCreate "root "clickWin [Click that button!!!] 0 0 100 100 []
Make "i 0
Line 1,981 ⟶ 2,334:
ifelse :i=1 [staticUpdate "clickSt (list "clicked :i "time)] ~
[staticUpdate "clickSt (list "clicked :i "times)]]
end</
The window is opened with:
<syntaxhighlight lang
=={{header|Lua}}==
<
l = iup.label{title="There have been no clicks yet."}
b = iup.button{title="Click me!"}
Line 2,000 ⟶ 2,353:
if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
iup.MainLoop()
end</
=={{header|M2000 Interpreter}}==
Line 2,010 ⟶ 2,363:
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Declare Form1 Form
Line 2,029 ⟶ 2,382:
}
Checkit
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
CreateDialog[{Dynamic@
TextCell@If[n == 0, "There have been no clicks yet", n],
Button["click me", n++]}]]</
=={{header|MAXScript}}==
<
(
label l "There have been no clicks yet"
Line 2,050 ⟶ 2,403:
)
)
createDialog buttonClick</
=={{header|Modula-3}}==
Line 2,056 ⟶ 2,409:
This code uses <tt>Trestle</tt>, a windowing toolkit developed for Modula-3.
<
IMPORT Fmt, TextVBT, ButtonVBT, VBT, Axis, HVSplit, TrestleComm, Trestle;
Line 2,075 ⟶ 2,428:
Trestle.Install(main);
Trestle.AwaitDelete(main);
END Click.</
To compile the above code, you need to create a file called <tt>m3makefile</tt> which contains:
Line 2,086 ⟶ 2,439:
=={{header|Nanoquery}}==
<
// define the necessary objects
Line 2,120 ⟶ 2,473:
// show the window
$w.show()</
=={{header|Nim}}==
{{libheader|GTK2}}
<
nim_init()
Line 2,146 ⟶ 2,499:
discard button.signal_connect("clicked", SignalFunc clickedMe, label)
win.showAll()
main()</
=={{header|Objective-C}}==
{{works with|GNUstep}}
<
#include <AppKit/AppKit.h>
Line 2,162 ⟶ 2,515:
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification;
- (void)advanceCounter: (id)sender;
@end</
<
-(instancetype) init
{
Line 2,234 ⟶ 2,587:
}
return 0;
}</
=={{header|OCaml}}==
* with '''Labltk''', the '''Tk''' OCaml binding:
<
#load "labltk.cma"
Line 2,253 ⟶ 2,606:
Tk.pack [Tk.coe label; Tk.coe b];
Tk.mainLoop ();
;;</
* with '''LablGTK2''', the '''GTK2''' OCaml binding:
<
let window = GWindow.window ~border_width:2 ()
Line 2,268 ⟶ 2,621:
button#connect#clicked ~callback:window#destroy;
window#show ();
Main.main ()</
=={{header|ooRexx}}==
<
* 18.06.2014 Walter Pachl shortened from Rony Flatscher's bsf4oorexx (see sourceforge) samples
* Look there for ShowCount.rxj
Line 2,355 ⟶ 2,708:
Otherwise how_often=userData~i 'times'
End
userData~label~setText("Button was pressed" how_often) -- display text</
=={{header|Oz}}==
<
import
Application
Line 2,376 ⟶ 2,729:
{Window show}
end
</syntaxhighlight>
=={{header|Pascal}}==
Line 2,384 ⟶ 2,737:
{{libheader|Gtk2}}
Ported from the C example.
<
uses
Line 2,430 ⟶ 2,783:
Gtk_widget_show_all(Gtk_WIDGET(win));
Gtk_main();
end.</
=={{header|Perl}}==
==={{libheader|Perl/Tk}}===
<
$main = MainWindow->new;
Line 2,443 ⟶ 2,796:
-command => sub { $l->configure(-text => 'Number of clicks: '.(++$count).'.'); },
)->pack;
MainLoop();</
==={{libheader|GTK}} {{works with|Perl/Gtk}}===
<
# Window.
Line 2,472 ⟶ 2,825:
# Main loop.
Gtk->main;</
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/simplewindow.htm here].
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Simple_window.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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,501 ⟶ 2,857:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
The above is cross platform,
An older win32-only version can be found [[Simple_windowed_application/Arwen|here]].
=={{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,545 ⟶ 2,882:
(server 8080 "!start")
(wait)</
=={{header|Pike}}==
{{libheader|Gtk2}}
<
int clicks;
Line 2,570 ⟶ 2,907:
return -1;
}
</syntaxhighlight>
=={{header|PowerShell}}==
===Windows Forms===
{{works with|PowerShell|3}}
<syntaxhighlight lang="powershell">
$Label1 = [System.Windows.Forms.Label]@{
Text = 'There have been no clicks yet'
Line 2,596 ⟶ 2,933:
$Result = $Form1.ShowDialog()
</syntaxhighlight>
{{works with|PowerShell|2}}
<syntaxhighlight lang="powershell">
Add-Type -AssemblyName System.Windows.Forms
Line 2,622 ⟶ 2,959:
$Result = $Form1.ShowDialog()
</syntaxhighlight>
===WPF===
<syntaxhighlight lang="powershell">
[xml]$Xaml = @"
<Window
Line 2,663 ⟶ 3,000:
$Result = $Window1.ShowDialog()
</syntaxhighlight>
=={{header|Processing}}==
<syntaxhighlight lang="java">
//Aamrun, 11th July 2022
int labelLeft = 100, labelTop = 100, labelWidth = 440, labelHeight = 100;
int labelTextLeft = 150, labelTextTop = 150;
int buttonLeft = 170, buttonTop = 230, buttonWidth = 300, buttonHeight = 100;
boolean hasBeenClicked = false;
int clicks = 0;
void setup(){
size(640,480);
fill(255);
rect(labelLeft,labelTop,labelWidth,labelHeight);
fill(0);
textSize(30);
text("There have been no clicks yet",labelTextLeft,labelTextTop);
fill(#c0c0c0);
rect(buttonLeft,buttonTop,buttonWidth,buttonHeight);
fill(0);
text("Click Me !", buttonLeft + 50,buttonTop + 50);
}
void mousePressed(){
if(mouseX > buttonLeft && mouseX < buttonLeft + buttonWidth
&& mouseY > buttonTop && mouseY < buttonTop + buttonHeight){
hasBeenClicked = true;
clicks++;
}
}
void draw(){
if(hasBeenClicked == true){
fill(255);
rect(labelLeft,labelTop,labelWidth,labelHeight);
fill(0);
textSize(30);
text("Clicks : " + str(clicks),labelTextLeft,labelTextTop);
}
}
</syntaxhighlight>
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
<
dialog('Simple windowed application',
Line 2,709 ⟶ 3,095:
send(D, open).
</syntaxhighlight>
=={{header|PureBasic}}==
<
Define window_0_Text_0, window_0_Button_1
Define clicks, txt$, flags
Line 2,738 ⟶ 3,124:
EndSelect
ForEver
EndIf</
=={{header|Python}}==
Line 2,744 ⟶ 3,130:
==={{libheader|Tkinter}}===
{{works with|Python|3.7}}
<
import tkinter as tk
Line 2,770 ⟶ 3,156:
if __name__ == '__main__':
main()
</syntaxhighlight>
The same in OO manner:
<
class ClickCounter(tk.Frame):
Line 2,794 ⟶ 3,180:
if __name__ == "__main__":
ClickCounter().mainloop()
</syntaxhighlight>
==={{libheader|PyQt}}===
<
from itertools import count
Line 2,833 ⟶ 3,219:
if __name__ == '__main__':
main()
</syntaxhighlight>
==={{libheader|wxPython}}===
<
Line 2,871 ⟶ 3,257:
frame.Show()
app.MainLoop()
</syntaxhighlight>
=={{header|R}}==
Line 2,879 ⟶ 3,265:
gWidgetsRGtk2 or gWidgetsrJava can be used as an alternative to gWidgetstcltk.
<
library(gWidgetstcltk)
win <- gwindow()
Line 2,888 ⟶ 3,274:
svalue(lab) <- ifelse(is.na(val) ,"1", as.character(val + 1))
}
)</
=={{header|Racket}}==
<
#lang racket/gui
Line 2,904 ⟶ 3,290:
(new button% [parent frame] [label "Click me"] [callback cb])
(send frame show #t)
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
{{libheader|GTK}}
<syntaxhighlight lang="raku"
use GTK::Simple::App;
Line 2,930 ⟶ 3,316:
}
$app.run;</
=={{header|RapidQ}}==
RapidQ has form designer that produces RapidQ Basic source code. You can get the same result by writing the code yourself with a text editor. Then compile it either from within IDE or by using the command line compiler.
<
CREATE form AS QForm
Line 2,960 ⟶ 3,346:
END SUB
form.ShowModal</
=={{header|REBOL}}==
<
Title: "Simple Windowed Application"
URL: http://rosettacode.org/wiki/Simple_Windowed_Application
Line 2,989 ⟶ 3,375:
set-face label reform ["clicks:" clicks]
]
]</
=={{header|Red}}==
<syntaxhighlight lang="red">Red []
clicks: 0
view [
t: text "There have been no clicks yet" return
button "click me" [
clicks: clicks + 1
t/data: rejoin ["clicks: " clicks]
]
]</syntaxhighlight>
=={{header|Ring}}==
<
Load "guilib.ring"
Line 3,014 ⟶ 3,413:
num += 1
lineedit1.settext( "you clicked me " + num + " times")
</syntaxhighlight>
Output:
Line 3,021 ⟶ 3,420:
=={{header|Ruby}}==
{{libheader|Ruby/Tk}}
<
str = TkVariable.new("no clicks yet")
count = 0
Line 3,031 ⟶ 3,430:
pack
end
Tk.mainloop</
{{libheader|Shoes}}
<
stack do
@count = 0
Line 3,043 ⟶ 3,442:
end
end
end</
=={{header|Run BASIC}}==
<
[loop] cls ' clear screen
print msg$
Line 3,055 ⟶ 3,454:
clicks = clicks + 1
msg$ = "Button has been clicked ";clicks;" times"
goto [loop]</
=={{header|Rust}}==
{{libheader|iced}}
<
button, Button, Column, Element, Length,
Text, Sandbox, Settings, Space,
Line 3,112 ⟶ 3,511:
settings.window.size = (600, 400);
Simple::run(settings).unwrap();
}</
=={{header|Scala}}==
{{libheader|Scala}}
<
import scala.swing.event.ButtonClicked
Line 3,137 ⟶ 3,536:
}
}
}</
=={{header|Scratch}}==
<syntaxhighlight lang="scratch">
when flag clicked # when program is run
set counter to "0" # initialize counter object to zero
set message to "There have been no clicks"
show variable message # show the message object
when this sprite clicked # when button clicked
hide message # hide the initial message
change counter by 1 # increment the counter object
</syntaxhighlight>
'''Comments and Description:'''<br>
The Scratch IDE has a GUI drag and drop interface.
The program above is has both graphic and text objects.
The 'message' and 'counter' variables coded above are also graphic objects.
They are set to "large readout" rather than slider or normal.
The (implied) 'sprite' has a 'costume' set to "button".
[https://www.melellington.com/simplewindow/scratchoutput.jpg Scratch-Output]
=={{header|Sidef}}==
===Gtk2===
<syntaxhighlight lang="ruby">require('Gtk2') -> init
# Window.
Line 3,166 ⟶ 3,588:
# Main loop.
%s<Gtk2>.main</
===Gtk3===
<syntaxhighlight lang="ruby">use('Gtk3 -init')
# Window.
var window = %O'Gtk3::Window'.new
window.signal_connect('destroy' => { %O'Gtk3'.main_quit })
# VBox.
var vbox = %O'Gtk3::VBox'.new(0, 0)
window.add(vbox)
# Label.
var label = %O'Gtk3::Label'.new('There have been no clicks yet.')
vbox.add(label)
# Button.
var count = 0
var button = %O'Gtk3::Button'.new(' Click Me ');
vbox.add(button)
button.signal_connect('clicked' => {
label.set_text(++count)
})
# Show.
window.show_all
# Main loop.
%O'Gtk3'.main</syntaxhighlight>
=={{header|Smalltalk}}==
{{works with|Smalltalk/X}}
<
clickCount := 0.
Line 3,185 ⟶ 3,636:
].
top open</
=={{header|Standard ML}}==
Works with PolyML
<
open Motif ;
Line 3,216 ⟶ 3,667:
end;
</syntaxhighlight>
call
countWindow () ;
Line 3,223 ⟶ 3,674:
=={{header|Tcl}}==
{{libheader|Tk}}
<
pack [label .l -text "There have been no clicks yet"]
set count 0
Line 3,229 ⟶ 3,680:
proc upd {} {
.l configure -text "Number of clicks: [incr ::count]"
}</
=={{header|TI-89 BASIC}}==
Line 3,235 ⟶ 3,686:
The Ti-89 does not have general onscreen buttons; this program uses the OK/Cancel choice of a dialog box to implement the UI.
<
Local clicks
0 → clicks
Line 3,246 ⟶ 3,697:
clicks + 1 → clicks
EndWhile
EndPrgm</
=={{header|Unicon}}==
<
import gui
$include "guih.icn"
Line 3,282 ⟶ 3,733:
d.show_modal()
end
</syntaxhighlight>
=={{header|Vala}}==
<syntaxhighlight lang="vala">// GTK 4
public class Example : Gtk.Application {
public Example() {
Object(application_id: "my.application",
flags: ApplicationFlags.FLAGS_NONE);
activate.connect(() => {
var window = new Gtk.ApplicationWindow(this);
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 20);
var label = new Gtk.Label("There have been no clicks yet");
var button = new Gtk.Button.with_label("click me");
var clicks = 0;
button.clicked.connect(() => {
clicks++;
label.label = "Button clicked " + clicks.to_string() + " times";
});
box.append(label);
box.append(button);
window.set_child(box);
window.present();
});
}
public static int main(string[] argv) {
return new Example().run(argv);
}
}</syntaxhighlight>
=={{header|Vedit macro language}}==
<
#1 = 0
repeat (ALL) {
Line 3,297 ⟶ 3,775:
Reg_Set(10, "Clicked", INSERT)
Reg_Set(10, " times", APPEND)
}</
=={{header|Visual Basic}}==
In VB, windows are usually created in the IDE. The generated code is hidden from the user unless viewed outside of VB. For the sake of this task, I have included that code, but normally it is hidden from the programmer.
<
Begin VB.Form Form2
Caption = "There have been no clicks yet"
Line 3,334 ⟶ 3,812:
Me.Caption = clicked & " clicks."
End Sub
</syntaxhighlight>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Zig">
import ui
import gx
[heap]
struct App {
mut:
window &ui.Window = unsafe {nil}
counter string = "No clicks yet" // will contain number count
}
fn main() {
mut app := &App{}
app.window = ui.window(
width: 200
height: 40
title: "Counter"
mode: .resizable
layout: ui.row(
spacing: 5
margin_: 10
widths: ui.stretch
heights: ui.stretch
children: [
ui.label(
id: "num"
text: &app.counter //refer to struct App
),
ui.button(
text: "Click me"
bg_color: gx.light_gray
radius: 5
border_color: gx.gray
on_click: app.btn_click //refer to function below
),
]
)
)
ui.run(app.window)
}
fn (mut app App) btn_click(btn &ui.Button) {
mut lbl := app.window.get_or_panic[ui.Label]("num") //"num" is id of label
app.counter = (app.counter.int() + 1).str() //change to string for label display
lbl.set_text(app.counter)
}
</syntaxhighlight>
=={{header|Web 68}}==
<
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
Line 3,437 ⟶ 3,964:
The predefined form was created by the <b>fdesign</b> program for the Xforms library,
and the resulting form definition file was converted to Web 68 by the program
<b>fdtow68</b>.</
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
import "input" for Mouse
import "dome" for Window
class SimpleWindowedApplication {
construct new(width, height) {
Window.title = "Simple windowed application"
_fore = Color.white
_clicks = 0
}
init() {
drawControls()
}
update() {
if (Mouse["left"].justPressed && insideButton) _clicks = _clicks + 1
}
draw(alpha) {
drawControls()
}
insideButton {
var p = Mouse.position
return p.x >= 120 && p.x <= 200 && p.y >= 90 && p.y <= 170
}
drawControls() {
Canvas.cls()
if (_clicks == 0) {
Canvas.print("There have been no clicks yet", 40, 40, _fore)
} else if (_clicks == 1) {
Canvas.print("The button has been clicked once", 30, 40, _fore)
} else {
Canvas.print("The button has been clicked %(_clicks) times", 10, 40, _fore)
}
Canvas.rectfill(120, 90, 80, 80, Color.red)
Canvas.rect(120, 90, 80, 80, Color.blue)
Canvas.print("click me", 130, 125, _fore)
}
}
var Game = SimpleWindowedApplication.new(600, 600)</syntaxhighlight>
=={{header|XPL0}}==
<
def Ww=40, Wh=12, Wx=(80-Ww)/2, Wy=(25-Wh)/2; \window width, etc.
def Bw=11, Bh=4, Bx=Wx+(Ww-Bw)/2, By=Wy+3*(Wh-Bh)/4; \button size & position
Line 3,469 ⟶ 4,043:
until ChkKey; \keystroke terminates program
SetVid(3); \turn off mouse and turn on flashing cursor
]</
=={{header|Yorick}}==
Yorick does not include a GUI toolkit. However, it does provide a plotting system that can emulate some basic GUI features, such as buttons and labels. The above sample uses a built-in library "button.i", which is itself written in Yorick.
<
window, 0;
Line 3,495 ⟶ 4,069:
winkill, 0;
}
} while(!finished);</
{{omit from|ACL2}}
{{omit from|AWK}}
{{omit from|Batch File|Does not have access to GUI functions.}}
{{omit from|EasyLang}}
{{omit from|GUISS}}
{{omit from|Logtalk}}
|