all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
1
Task/Simple-windowed-application/0DESCRIPTION
Normal file
1
Task/Simple-windowed-application/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
This task asks to create a window with a label that says "There have been no clicks yet" and a button that says "click me". Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
|
||||
6
Task/Simple-windowed-application/1META.yaml
Normal file
6
Task/Simple-windowed-application/1META.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
category:
|
||||
- Basic language learning
|
||||
note: GUI
|
||||
requires:
|
||||
- Graphics
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
with Gdk.Event; use Gdk.Event;
|
||||
with Gtk.Button; use Gtk.Button;
|
||||
with Gtk.Label; use Gtk.Label;
|
||||
with Gtk.Window; use Gtk.Window;
|
||||
with Gtk.Widget; use Gtk.Widget;
|
||||
with Gtk.Table; use Gtk.Table;
|
||||
|
||||
with Gtk.Handlers;
|
||||
with Gtk.Main;
|
||||
|
||||
procedure Simple_Windowed_Application is
|
||||
Window : Gtk_Window;
|
||||
Grid : Gtk_Table;
|
||||
Button : Gtk_Button;
|
||||
Label : Gtk_Label;
|
||||
Count : Natural := 0;
|
||||
|
||||
package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
|
||||
package Return_Handlers is
|
||||
new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
|
||||
|
||||
function Delete_Event (Widget : access Gtk_Widget_Record'Class)
|
||||
return Boolean is
|
||||
begin
|
||||
return False;
|
||||
end Delete_Event;
|
||||
|
||||
procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
|
||||
begin
|
||||
Gtk.Main.Main_Quit;
|
||||
end Destroy;
|
||||
|
||||
procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
|
||||
begin
|
||||
Count := Count + 1;
|
||||
Set_Text (Label, "The button clicks:" & Natural'Image (Count));
|
||||
end Clicked;
|
||||
|
||||
begin
|
||||
Gtk.Main.Init;
|
||||
Gtk.Window.Gtk_New (Window);
|
||||
Gtk_New (Grid, 1, 2, False);
|
||||
Add (Window, Grid);
|
||||
Gtk_New (Label, "There have been no clicks yet");
|
||||
Attach (Grid, Label, 0, 1, 0, 1);
|
||||
Gtk_New (Button, "Click me");
|
||||
Attach (Grid, Button, 0, 1, 1, 2);
|
||||
Return_Handlers.Connect
|
||||
( Window,
|
||||
"delete_event",
|
||||
Return_Handlers.To_Marshaller (Delete_Event'Access)
|
||||
);
|
||||
Handlers.Connect
|
||||
( Window,
|
||||
"destroy",
|
||||
Handlers.To_Marshaller (Destroy'Access)
|
||||
);
|
||||
Handlers.Connect
|
||||
( Button,
|
||||
"clicked",
|
||||
Handlers.To_Marshaller (Clicked'Access)
|
||||
);
|
||||
Show_All (Grid);
|
||||
Show (Window);
|
||||
|
||||
Gtk.Main.Main;
|
||||
end Simple_Windowed_Application;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
; Create simple windowed application
|
||||
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
|
||||
Gui, Show, , Simple windowed application ; show the Window
|
||||
Return ; end of the auto-execute section
|
||||
|
||||
ButtonClick: ; the subroutine executed each time the Button-Control is clicked
|
||||
count++ ; increment the click-counting var
|
||||
GuiControl, , TextCtl, %count% ; update the Text-Control with the click-counting var
|
||||
Return ; end of the subroutine
|
||||
|
||||
GuiClose: ; the subroutine executed when the Window is closed
|
||||
ExitApp ; exit this process
|
||||
Return
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
INSTALL @lib$+"WINLIB2"
|
||||
INSTALL @lib$+"WINLIB5"
|
||||
|
||||
window% = FN_newdialog("Rosetta Code", 100, 100, 120, 52, 8, 1000)
|
||||
PROC_static(window%, "There have been no clicks yet", 100, 10, 10, 100, 14, 0)
|
||||
PROC_pushbutton(window%, "Click me", FN_setproc(PROCclick), 40, 30, 40, 16, 0)
|
||||
PROC_showdialog(window%)
|
||||
|
||||
REPEAT
|
||||
WAIT 1
|
||||
UNTIL !window% = 0
|
||||
QUIT
|
||||
|
||||
DEF PROCclick
|
||||
PRIVATE clicks%
|
||||
clicks% += 1
|
||||
SYS "SetDlgItemText", !window%, 100, "Number of clicks = " + STR$(clicks%)
|
||||
ENDPROC
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef CLICKCOUNTER_H
|
||||
#define CLICKCOUNTER_H
|
||||
|
||||
#include <QWidget>
|
||||
class QLabel ;
|
||||
class QPushButton ;
|
||||
class QVBoxLayout ;
|
||||
|
||||
class Counter : public QWidget {
|
||||
Q_OBJECT
|
||||
public :
|
||||
Counter( QWidget * parent = 0 ) ;
|
||||
private :
|
||||
int number ;
|
||||
QLabel *countLabel ;
|
||||
QPushButton *clicker ;
|
||||
QVBoxLayout *myLayout ;
|
||||
private slots :
|
||||
void countClicks( ) ;
|
||||
} ;
|
||||
#endif
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include "clickcounter.h"
|
||||
|
||||
Counter::Counter( QWidget * parent ) : QWidget( parent ) {
|
||||
number = 0 ;
|
||||
countLabel = new QLabel( "There have been no clicks yet!" ) ;
|
||||
clicker = new QPushButton( "click me" ) ;
|
||||
connect ( clicker , SIGNAL( clicked( ) ) , this , SLOT( countClicks( ) ) ) ;
|
||||
myLayout = new QVBoxLayout ;
|
||||
myLayout->addWidget( countLabel ) ;
|
||||
myLayout->addWidget( clicker ) ;
|
||||
setLayout( myLayout ) ;
|
||||
}
|
||||
|
||||
void Counter::countClicks( ) {
|
||||
number++ ;
|
||||
countLabel->setText( QString( "The button has been clicked %1 times!").arg( number ) ) ;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#include <QApplication>
|
||||
#include "clickcounter.h"
|
||||
|
||||
int main( int argc , char *argv[ ] ) {
|
||||
QApplication app( argc , argv ) ;
|
||||
Counter counter ;
|
||||
counter.show( ) ;
|
||||
return app.exec( ) ;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#include <stdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
const gchar *clickme = "Click Me";
|
||||
guint counter = 0;
|
||||
|
||||
#define MAXLEN 64
|
||||
void clickedme(GtkButton *o, gpointer d)
|
||||
{
|
||||
GtkLabel *l = GTK_LABEL(d);
|
||||
char nt[MAXLEN];
|
||||
|
||||
counter++;
|
||||
snprintf(nt, MAXLEN, "You clicked me %d times", counter);
|
||||
gtk_label_set_text(l, nt);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
GtkWindow *win;
|
||||
GtkButton *button;
|
||||
GtkLabel *label;
|
||||
GtkVBox *vbox;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
win = (GtkWindow*)gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(win, clickme);
|
||||
button = (GtkButton*)gtk_button_new_with_label(clickme);
|
||||
label = (GtkLabel*)gtk_label_new("There have been no clicks yet");
|
||||
gtk_label_set_single_line_mode(label, TRUE);
|
||||
vbox = (GtkVBox*)gtk_vbox_new(TRUE, 1);
|
||||
gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(label));
|
||||
gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(button));
|
||||
gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(vbox));
|
||||
g_signal_connect(G_OBJECT(win), "delete-event", (GCallback)gtk_main_quit, NULL);
|
||||
g_signal_connect(G_OBJECT(button), "clicked", (GCallback)clickedme, label);
|
||||
gtk_widget_show_all(GTK_WIDGET(win));
|
||||
gtk_main();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
(ns counter-window
|
||||
(:import (javax.swing JFrame JLabel JButton)))
|
||||
|
||||
(defmacro on-action [component event & body]
|
||||
`(. ~component addActionListener
|
||||
(proxy [java.awt.event.ActionListener] []
|
||||
(actionPerformed [~event] ~@body))))
|
||||
|
||||
(defn counter-app []
|
||||
(let [counter (atom 0)
|
||||
label (JLabel. "There have been no clicks yet")
|
||||
button (doto (JButton. "Click me!")
|
||||
(on-action evnt
|
||||
(.setText label
|
||||
(str "Counter: " (swap! counter inc)))))
|
||||
panel (doto (JPanel.)
|
||||
(.setOpaque true)
|
||||
(.add label)
|
||||
(.add button))]
|
||||
(doto (JFrame. "Counter App")
|
||||
(.setContentPane panel)
|
||||
(.setSize 300 100)
|
||||
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
|
||||
(.setVisible true))))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(defpackage #:rcswa
|
||||
(:use #:clim #:clim-lisp))
|
||||
(in-package #:rcswa)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
(define-application-frame simple-windowed-application ()
|
||||
((clicks :initform 0
|
||||
:accessor clicks-of))
|
||||
(:menu-bar t)
|
||||
(:pane
|
||||
(make-pane 'application-pane
|
||||
:width '(40 :character)
|
||||
:height '(3 :character)
|
||||
:display-time :command-loop
|
||||
:display-function
|
||||
(lambda (pane stream)
|
||||
(declare (ignore pane))
|
||||
(format stream "~[There have been no clicks yet.~
|
||||
~:;~:*There ~[have~;has~:;have~]~:* been ~R click~:P.~]"
|
||||
(clicks-of *application-frame*))))))
|
||||
|
||||
(define-simple-windowed-application-command (com-click-me :menu t)
|
||||
()
|
||||
(incf (clicks-of *application-frame*)))
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
(define-application-frame simple-windowed-application ()
|
||||
((clicks :initform 0
|
||||
:accessor clicks-of))
|
||||
(:panes
|
||||
(the-label :application
|
||||
:width '(40 :character)
|
||||
:height '(3 :character)
|
||||
:display-time t
|
||||
:display-function
|
||||
(lambda (pane stream)
|
||||
(declare (ignore pane))
|
||||
(format stream "~[There have been no clicks yet.~
|
||||
~:;~:*There ~[have~;has~:;have~]~:* been ~R click~:P.~]"
|
||||
(clicks-of *application-frame*))))
|
||||
(the-button :push-button
|
||||
:label "Click Me"
|
||||
:activate-callback
|
||||
(lambda (button)
|
||||
(declare (ignore button))
|
||||
(incf (clicks-of *application-frame*))
|
||||
(redisplay-frame-pane *application-frame*
|
||||
(find-pane-named *application-frame* 'the-label)
|
||||
:force-p t))))
|
||||
(:layouts (default
|
||||
(vertically (:equalize-width nil :align-x :center)
|
||||
the-label
|
||||
(spacing (:thickness 10) the-button)))))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(run-frame-top-level (make-application-frame 'simple-windowed-application))
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
module winapp ;
|
||||
import dfl.all ;
|
||||
import std.string ;
|
||||
|
||||
class MainForm: Form {
|
||||
Label label ;
|
||||
Button button ;
|
||||
this() {
|
||||
width = 240 ;
|
||||
with(label = new Label) {
|
||||
text = "There have been no clicks yet" ;
|
||||
dock = DockStyle.TOP ;
|
||||
parent = this ;
|
||||
}
|
||||
with(button = new Button) {
|
||||
dock = DockStyle.BOTTOM ;
|
||||
text = "Click Me" ;
|
||||
parent = this ;
|
||||
click ~= &onClickButton ;
|
||||
}
|
||||
height = label.height + button.height + 36 ;
|
||||
}
|
||||
private void onClickButton(Object sender, EventArgs ea) {
|
||||
static int count = 0 ;
|
||||
label.text = "You had been clicked me " ~ std.string.toString(++count) ~ " times." ;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
Application.run(new MainForm);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
module SimpleWindow;
|
||||
import tango.text.convert.Integer;
|
||||
import tango.core.Thread; // For Thread.yield
|
||||
|
||||
import xf.hybrid.Hybrid; //For widgets and general API
|
||||
import xf.hybrid.backend.GL; // For OpenGL Renderer
|
||||
|
||||
void main() {
|
||||
//load config file
|
||||
scope cfg = loadHybridConfig(`./SimpleWindow.cfg`);
|
||||
scope renderer = new Renderer;
|
||||
auto counter = 0;
|
||||
|
||||
bool programRunning = true;
|
||||
while (programRunning) {
|
||||
// Tell Hybrid what config to use
|
||||
gui.begin(cfg);
|
||||
// Exit program if user clicks the Close button
|
||||
if (gui().getProperty!(bool)("main.frame.closeClicked")) {
|
||||
programRunning = false;
|
||||
}
|
||||
// Update text on the label
|
||||
if (counter != 0)
|
||||
Label("main.label").text = toString(counter);
|
||||
// Increment counter if the button has been clicked
|
||||
if (Button("main.button").clicked) {
|
||||
counter++;
|
||||
}
|
||||
// Finalize. Prepare to render
|
||||
gui.end();
|
||||
// Render window using OpenGL Renderer
|
||||
gui.render(renderer);
|
||||
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
-- begin file --
|
||||
|
||||
Program SingleWinApp ;
|
||||
|
||||
// This is the equivalent of the C #include
|
||||
Uses Forms, Windows, Messages, Classes, Graphics, Controls, StdCtrls ;
|
||||
|
||||
|
||||
type
|
||||
|
||||
// The only reason for this declaration is to allow the connection of the
|
||||
// on click method to the forms button object. This class declaration adds
|
||||
// a procedure.
|
||||
|
||||
TMainForm class(tform)
|
||||
Procedure AddClicks(sender : tObject);
|
||||
end;
|
||||
|
||||
|
||||
// Use these globals.
|
||||
var
|
||||
|
||||
MainForm : tForm ;
|
||||
aLabel : tLabel ;
|
||||
aButton : tButton ;
|
||||
i : integer = 0 ;
|
||||
|
||||
|
||||
// This is the Method call that we connect to the button object
|
||||
// to start counting the clicks.
|
||||
Procedure tMainForm.AddClicks(sender :tObject)
|
||||
begin
|
||||
inc(i);
|
||||
aLabel.Caption := IntToStr(i) + ' Clicks since startup' ;
|
||||
end;
|
||||
|
||||
|
||||
Begin
|
||||
// Do all the behind the scenes stuff that sets up the Windows environment
|
||||
Application.Initialize ;
|
||||
|
||||
// Create the form
|
||||
|
||||
// Forms can either be created with an owner, like I have done here, or with
|
||||
// the owner set to Nil. In pascal (all versions of Borland) '''NIL''' is a
|
||||
// reserved, (the equivalent of '''NULL''' in Ansi C) word and un-sets any pointer
|
||||
// variable. Setting the owner to the application object will ensure that the form is
|
||||
// freed by the application object when the application shuts down. If I had set
|
||||
// the owner to NIL then i would have had to make sure I freed the form explicitly
|
||||
// or it would have been orphaned, thus creating a memory leak.
|
||||
|
||||
// I must direct your attention to the CreateNew constructor. This is
|
||||
// a non standard usage. Normally the constructor Create() will call this
|
||||
// as part of the initialization routine for the form. Normally as you drop
|
||||
// various components on a form in deign mode, a DFM file is created with
|
||||
// all the various initial states of the controls. This bypasses the
|
||||
// DFM file altogether although all components AND the form are created
|
||||
// with default values. (see the Delphi help file).
|
||||
|
||||
MainForm := tMainForm.CreateNew(Application);
|
||||
MainForm.Parent := Application ;
|
||||
MainForm.Position := poScreenCenter ;
|
||||
MainForm.Caption := 'Single Window Application' ;
|
||||
|
||||
// Create the Label, set its owner as MaiaForm
|
||||
aLabel := tLabel.Create(mainForm);
|
||||
aLabel.Parent := MainForm;
|
||||
aLabel.Caption := IntToStr(i) + ' Clicks since startup' ;
|
||||
aLabel.Left := 20 ;
|
||||
aLabel.Top := MainForm.ClientRect.Bottom div 2 ;
|
||||
|
||||
// Create the button, set its owner to MainForm
|
||||
aButton := tButton.Create(MainForm);
|
||||
aButton.Parent := MainForm ;
|
||||
aButton.Caption := 'Click Me!';
|
||||
aButton.Left := (MainForm.ClientRect.Right div 2)-(aButton.Width div 2 );
|
||||
aButton.Top := MainForm.ClientRect.Bottom - aButton.Height - 10 ;
|
||||
aButton.OnClick := AddClicks ;
|
||||
|
||||
// Show the main form, Modaly. The ONLY reason to do this is because in this
|
||||
// demonstration if you only call the SHOW method, the form will appear and
|
||||
// disappear in a split second.
|
||||
MainForm.ShowModal ;
|
||||
|
||||
Application.Run ;
|
||||
|
||||
end. // Program
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
when (currentVat.morphInto("awt")) -> {
|
||||
var clicks := 0
|
||||
def w := <swing:makeJFrame>("Rosetta Code 'Simple Windowed Application'")
|
||||
w.setContentPane(JPanel`
|
||||
${def l := <swing:makeJLabel>("There have been no clicks yet.")} $\
|
||||
${def b := <swing:makeJButton>("Click Me")}
|
||||
`)
|
||||
b.addActionListener(def _ {
|
||||
to actionPerformed(_) {
|
||||
clicks += 1
|
||||
l.setText(`Number of clicks: $clicks`)
|
||||
}
|
||||
})
|
||||
w.pack()
|
||||
w.show()
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
include EuWinGUI.ew
|
||||
|
||||
Window("EuWinGUI - Simple windowed application",100,100,360,100)
|
||||
constant Button1 = Control(Button,"Click me",250,20,80,25)
|
||||
constant Label1 = Control(Label,"There have been no clicks yet",10,25,200,18)
|
||||
|
||||
integer clicks
|
||||
clicks = 0
|
||||
|
||||
-- Event loop
|
||||
while 1 do
|
||||
WaitEvent()
|
||||
if EventOwner = Button1 and Event = Click then
|
||||
clicks += 1
|
||||
SetText(Label1,sprintf("You clicked me %d times",clicks))
|
||||
end if
|
||||
end while
|
||||
|
||||
CloseApp(0)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
using fwt
|
||||
using gfx
|
||||
|
||||
class SimpleApplication
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
Window
|
||||
{
|
||||
title = "Simple Window Application"
|
||||
size = Size(350, 50)
|
||||
clicked := 0
|
||||
label := Label
|
||||
{
|
||||
text = "There have been no clicks yet"
|
||||
}
|
||||
Button
|
||||
{
|
||||
text = "Click me"
|
||||
onAction.add |Event e|
|
||||
{
|
||||
clicked += 1
|
||||
label.text = "There have been $clicked clicks"
|
||||
}
|
||||
},
|
||||
label,
|
||||
}.open
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
also minos
|
||||
text-label ptr click-label
|
||||
Variable click# click# off
|
||||
: click-win ( -- ) screen self window new window with
|
||||
X" There have been no clicks yet" text-label new
|
||||
dup F bind click-label
|
||||
^ S[ 1 click# +!
|
||||
click# @ 0 <# #S s" Number of clicks: " holds #>
|
||||
click-label assign ]S X" Click me" button new
|
||||
&2 vabox new panel s" Clicks" assign show endwith ;
|
||||
click-win
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
#! xbigforth
|
||||
\ automatic generated code
|
||||
\ do not edit
|
||||
|
||||
also editor also minos also forth
|
||||
|
||||
component class ccount
|
||||
public:
|
||||
early widget
|
||||
early open
|
||||
early dialog
|
||||
early open-app
|
||||
text-label ptr click#
|
||||
( [varstart] ) cell var clicks ( [varend] )
|
||||
how:
|
||||
: open new DF[ 0 ]DF s" Click counter" open-component ;
|
||||
: dialog new DF[ 0 ]DF s" Click counter" open-dialog ;
|
||||
: open-app new DF[ 0 ]DF s" Click counter" open-application ;
|
||||
class;
|
||||
|
||||
ccount implements
|
||||
( [methodstart] ) ( [methodend] )
|
||||
: widget ( [dumpstart] )
|
||||
X" There have been no clicks yet" text-label new ^^bind click#
|
||||
^^ S[ 1 clicks +!
|
||||
clicks @ 0 <# #S s" Number of clicks: " holds #> click# assign ]S ( MINOS ) X" Click me" button new
|
||||
&2 vabox new panel
|
||||
( [dumpend] ) ;
|
||||
: init ^>^^ assign widget 1 :: init ;
|
||||
class;
|
||||
|
||||
: main
|
||||
ccount open-app
|
||||
$1 0 ?DO stop LOOP bye ;
|
||||
script? [IF] main [THEN]
|
||||
previous previous previous
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
|
||||
window.SetTitle("Click me")
|
||||
label := gtk.Label("There have been no clicks yet")
|
||||
var clicks int
|
||||
button := gtk.ButtonWithLabel("click me")
|
||||
button.Clicked(func() {
|
||||
clicks++
|
||||
if clicks == 1 {
|
||||
label.SetLabel("Button clicked 1 time")
|
||||
} else {
|
||||
label.SetLabel(fmt.Sprintf("Button clicked %d times",
|
||||
clicks))
|
||||
}
|
||||
})
|
||||
vbox := gtk.VBox(false, 1)
|
||||
vbox.Add(label)
|
||||
vbox.Add(button)
|
||||
window.Add(vbox)
|
||||
window.Connect("destroy", func() {
|
||||
gtk.MainQuit()
|
||||
})
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import groovy.swing.SwingBuilder
|
||||
|
||||
count = 0
|
||||
new SwingBuilder().edt {
|
||||
frame(title:'Click frame', pack: true, show: true) {
|
||||
vbox {
|
||||
countLabel = label("There have been no clicks yet.")
|
||||
button('Click Me', actionPerformed: {count++; countLabel.text = "Clicked ${count} time(s)."})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import groovy.swing.SwingBuilder
|
||||
import groovy.beans.Bindable
|
||||
|
||||
@Bindable class Model {
|
||||
Integer count = 0
|
||||
}
|
||||
model = new Model()
|
||||
new SwingBuilder().edt {
|
||||
frame(title:'Click frame', pack: true, show: true) {
|
||||
vbox {
|
||||
label(text: bind(source: model, sourceProperty: 'count',
|
||||
converter: { v -> !v ? "There have been no clicks yet." : "Clicked ${v} time(s)."}))
|
||||
button('Click Me', actionPerformed: {model.count++})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import Graphics.UI.Gtk
|
||||
import Data.IORef
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
initGUI
|
||||
window <- windowNew
|
||||
window `onDestroy` mainQuit
|
||||
windowSetTitle window "Simple Windowed App"
|
||||
set window [ containerBorderWidth := 10 ]
|
||||
|
||||
hbox <- hBoxNew True 5
|
||||
|
||||
set window [ containerChild := hbox ]
|
||||
|
||||
lab <- labelNew (Just "There have been no clicks yet")
|
||||
button <- buttonNewWithLabel "Click me"
|
||||
set hbox [ containerChild := lab ]
|
||||
set hbox [ containerChild := button ]
|
||||
|
||||
m <- newIORef 0
|
||||
|
||||
onClicked button $ do
|
||||
v <- readIORef m
|
||||
writeIORef m (v+1)
|
||||
set lab [ labelText := "There have been " ++ show (v+1) ++ " clicks" ]
|
||||
|
||||
widgetShowAll window
|
||||
|
||||
mainGUI
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
CHARACTER label="There have been no clicks yet"
|
||||
|
||||
DO count = 1, 1E100 ! "forever"
|
||||
DLG(Button="Click me", Width=3, TItle=label) ! Width=3 to display full length label
|
||||
label = "Clicked " // count // "time(s)"
|
||||
ENDDO
|
||||
|
||||
END
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
pro counter, ev
|
||||
widget_control, ev.top, get_uvalue=tst
|
||||
tst[1] = tst[1]+1
|
||||
widget_control, tst[0], set_value="Number of clicks: "+string(tst[1],format='(i0)')
|
||||
widget_control, ev.top, set_uvalue=tst
|
||||
end
|
||||
|
||||
id = widget_base(title = 'Window Title',column=1)
|
||||
ld = widget_label(id, value = 'There have been no clicks yet.')
|
||||
widget_control, /realize, id, set_uvalue=[ld,0]
|
||||
dummy = widget_button(id,value=' Click Me ',event_pro='counter')
|
||||
xmanager, "Simple", Id
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
SIMPLEAPP=: noun define
|
||||
pc simpleApp;
|
||||
xywh 131 11 44 12;cc inc button;cn "Click me";
|
||||
xywh 7 10 115 11;cc shownText static;cn "There have been no clicks yet.";
|
||||
pas 6 6;pcenter;
|
||||
rem form end;
|
||||
)
|
||||
|
||||
simpleApp_run=: verb define
|
||||
wd SIMPLEAPP
|
||||
simpleApp_accum=: 0 NB. initialize accumulator
|
||||
wd 'pshow;'
|
||||
)
|
||||
|
||||
simpleApp_inc_button=: verb define
|
||||
wd 'set shownText *','Button-use count: ',": simpleApp_accum=: >: simpleApp_accum
|
||||
)
|
||||
|
||||
simpleApp_close=: wd bind 'pclose'
|
||||
simpleApp_cancel=: simpleApp_close
|
||||
|
||||
simpleApp_run''
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
public class Clicks extends JFrame implements ActionListener{
|
||||
private long clicks = 0;
|
||||
private JLabel label;
|
||||
private JButton clicker;
|
||||
private String text;
|
||||
|
||||
public Clicks(){
|
||||
text = "There have been no clicks yet";
|
||||
label = new JLabel(text);
|
||||
clicker = new JButton("click me");
|
||||
clicker.addActionListener(this);//listen to the button
|
||||
setLayout(new BorderLayout());//handles placement of components
|
||||
add(label,BorderLayout.CENTER);//add the label to the biggest section
|
||||
add(clicker,BorderLayout.SOUTH);//put the button underneath it
|
||||
setSize(300,200);//stretch out the window
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//stop the program on "X"
|
||||
setVisible(true);//show it
|
||||
}
|
||||
public static void main(String[] args){
|
||||
new Clicks();//call the constructor where all the magic happens
|
||||
}
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if(arg0.getSource() == clicker){//if they clicked the button
|
||||
text = "There have been " + (++clicks) + " clicks";
|
||||
label.setText(text);//change the text
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import javafx.stage.*;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.control.*;
|
||||
|
||||
Stage {
|
||||
scene: Scene {
|
||||
width: 300 height: 200
|
||||
content: VBox {
|
||||
var clicks: Integer;
|
||||
|
||||
spacing: 10
|
||||
content: [
|
||||
Label {
|
||||
def varText = bind if (clicks == 0) then "no clicks yet" else "{clicks} clicks"
|
||||
text : bind "There have been {varText}"
|
||||
}
|
||||
Button {
|
||||
text: "click me"
|
||||
onMouseClicked: function(e) { clicks++; }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
nomainwin
|
||||
button #demo.btn, "Click Me", [btnClick], UL, 20, 50
|
||||
statictext #demo.num, "There have been no clicks yet.", 20, 100, 240, 30
|
||||
open "Rosetta Task: Simple windowed application" for window as #demo
|
||||
#demo "trapclose [quit]"
|
||||
nClicks = 0
|
||||
wait
|
||||
|
||||
[quit]
|
||||
close #demo
|
||||
end
|
||||
|
||||
[btnClick]
|
||||
nClicks = nClicks + 1
|
||||
#demo.num "The button has been clicked ";nClicks;" times."
|
||||
wait
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
to clickwindow
|
||||
windowCreate "root "clickWin [Click that button!!!] 0 0 100 100 []
|
||||
Make "i 0
|
||||
staticCreate "clickWin "clickSt [There have been no clicks yet] 0 0 100 20
|
||||
buttonCreate "clickWin "clickBtn [click me] 10 20 80 20 ~
|
||||
[Make "i :i+1 ~
|
||||
ifelse :i=1 [staticUpdate "clickSt (list "clicked :i "time)] ~
|
||||
[staticUpdate "clickSt (list "clicked :i "times)]]
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
clickwindow
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
require"iuplua"
|
||||
l = iup.label{title="There have been no clicks yet."}
|
||||
b = iup.button{title="Click me!"}
|
||||
clicks = 0
|
||||
function b:button_cb()
|
||||
clicks = clicks + 1
|
||||
l.title = "There have been " .. clicks/2 .. " clicks so far." --yes, this is correct.
|
||||
end
|
||||
dlg = iup.dialog{iup.vbox{l, b}, title="Simple Windowed Application"}
|
||||
dlg:show()
|
||||
|
||||
if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
|
||||
iup.MainLoop()
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
rollout buttonClick "Button Click"
|
||||
(
|
||||
label l "There have been no clicks yet"
|
||||
button clickMe "Click me"
|
||||
local clickCount = 0
|
||||
|
||||
on clickMe pressed do
|
||||
(
|
||||
clickCount += 1
|
||||
l.text = ("Number of clicks: " + clickCount as string)
|
||||
)
|
||||
)
|
||||
createDialog buttonClick
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DynamicModule[{n = 0},
|
||||
CreateDialog[{Dynamic@
|
||||
TextCell@If[n == 0, "There have been no clicks yet", n],
|
||||
Button["click me", n++]}]]
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
MODULE Click EXPORTS Main;
|
||||
|
||||
IMPORT Fmt, TextVBT, ButtonVBT, VBT, Axis, HVSplit, TrestleComm, Trestle;
|
||||
|
||||
VAR label := TextVBT.New("There have been no clicks yet.");
|
||||
button := ButtonVBT.New(TextVBT.New("Click me!"), Clicked);
|
||||
main := HVSplit.Cons(Axis.T.Ver, label, button, adjustable := FALSE);
|
||||
count := 0;
|
||||
|
||||
PROCEDURE Clicked(<*UNUSED*>button: ButtonVBT.T; <*UNUSED*>READONLY cd: VBT.MouseRec) =
|
||||
BEGIN
|
||||
INC(count);
|
||||
TextVBT.Put(label, "Button pressed: " & Fmt.Int(count));
|
||||
END Clicked;
|
||||
|
||||
<*FATAL TrestleComm.Failure*>
|
||||
BEGIN
|
||||
Trestle.Install(main);
|
||||
Trestle.AwaitDelete(main);
|
||||
END Click.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#directory "+labltk"
|
||||
#load "labltk.cma"
|
||||
|
||||
let () =
|
||||
let top = Tk.openTk() in
|
||||
Wm.title_set top "Tk-OCaml Example";
|
||||
let label = Label.create ~text:"There have been no clicks yet" top in
|
||||
let b =
|
||||
Button.create
|
||||
~text:"click me"
|
||||
~command:(fun () -> Tk.closeTk (); exit 0)
|
||||
top
|
||||
in
|
||||
Tk.pack [Tk.coe label; Tk.coe b];
|
||||
Tk.mainLoop ();
|
||||
;;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
open GMain
|
||||
|
||||
let window = GWindow.window ~border_width:2 ()
|
||||
let vbox = GPack.vbox ~packing:window#add ()
|
||||
let label = GMisc.label ~text:"There have been no clicks yet" ~packing:vbox#pack ()
|
||||
let button = GButton.button ~label:"click me" ~packing:vbox#pack ()
|
||||
|
||||
let () =
|
||||
window#event#connect#delete ~callback:(fun _ -> true);
|
||||
window#connect#destroy ~callback:Main.quit;
|
||||
button#connect#clicked ~callback:window#destroy;
|
||||
window#show ();
|
||||
Main.main ()
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
@interface ClickMe : NSWindow
|
||||
{
|
||||
NSButton *button;
|
||||
NSTextField *text;
|
||||
int counter;
|
||||
}
|
||||
- (void)applicationDidFinishLaunching: (NSNotification *)notification;
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification;
|
||||
- (void)advanceCounter: (id)sender;
|
||||
@end
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
@implementation ClickMe : NSWindow
|
||||
-(id) init
|
||||
{
|
||||
NSRect buttonRect;
|
||||
int totalWindowHeight;
|
||||
|
||||
counter = 0;
|
||||
button = [[NSButton alloc] init];
|
||||
[button setButtonType: NSToggleButton];
|
||||
[button setTitle: @"Click Me"];
|
||||
[button sizeToFit];
|
||||
[button setTarget: self];
|
||||
[button setAction: @selector(advanceCounter:)];
|
||||
buttonRect = [button frame];
|
||||
|
||||
text = [[NSTextField alloc]
|
||||
initWithFrame: NSMakeRect(buttonRect.origin.x, buttonRect.size.height,
|
||||
buttonRect.size.width, buttonRect.size.height)];
|
||||
[text setAlignment: NSCenterTextAlignment];
|
||||
[text setEditable: NO];
|
||||
[text setStringValue: @"There have been no clicks yet"];
|
||||
[text sizeToFit];
|
||||
|
||||
// reset size of button according to size of (larger...?) text
|
||||
[button
|
||||
setFrameSize: NSMakeSize( [text frame].size.width, buttonRect.size.height ) ];
|
||||
|
||||
totalWindowHeight = buttonRect.size.height + [text frame].size.height;
|
||||
|
||||
[self
|
||||
initWithContentRect: NSMakeRect(100, 100,
|
||||
[text frame].size.width, totalWindowHeight)
|
||||
styleMask: (NSTitledWindowMask | NSClosableWindowMask)
|
||||
backing: NSBackingStoreBuffered
|
||||
defer: NO];
|
||||
|
||||
[[self contentView] addSubview: text]; [text release];
|
||||
[[self contentView] addSubview: button]; [button release];
|
||||
|
||||
[self setTitle: @"Click Me!"];
|
||||
[self center];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
-(void) dealloc
|
||||
{
|
||||
[button release];
|
||||
[text release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching: (NSNotification *)notification
|
||||
{
|
||||
[self orderFront: self];
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)advanceCounter: (id)sender
|
||||
{
|
||||
counter++;
|
||||
[text setStringValue: [NSString stringWithFormat: @"Clicked %d times", counter]];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
ClickMe *clickme;
|
||||
NSAutoreleasePool *pool;
|
||||
NSApplication *app;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
app = [NSApplication sharedApplication];
|
||||
clickme = [[ClickMe alloc] init];
|
||||
[app setDelegate: clickme];
|
||||
[app run];
|
||||
[clickme release];
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
functor
|
||||
import
|
||||
Application
|
||||
QTk at 'x-oz://system/wp/QTk.ozf'
|
||||
define
|
||||
Count = {NewCell 0}
|
||||
Label
|
||||
GUI = td(action:proc {$} {Application.exit 0} end %% exit on close
|
||||
label(text:"There have been no clicks yet." handle:Label)
|
||||
button(text:"Click Me"
|
||||
action:proc {$}
|
||||
Count := @Count + 1
|
||||
{Label set(text:"Number of clicks: "#@Count#".")}
|
||||
end
|
||||
))
|
||||
Window = {QTk.build GUI}
|
||||
{Window show}
|
||||
end
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
Program SimpleWindowApplication;
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
glib2,
|
||||
Gtk2;
|
||||
|
||||
const
|
||||
clickme = 'Click Me';
|
||||
MAXLEN = 64;
|
||||
|
||||
var
|
||||
counter: integer = 0;
|
||||
|
||||
procedure clickedme(o: PGtkButton; d: pointer); cdecl;
|
||||
var
|
||||
nt: Pchar;
|
||||
l: PGtkLabel;
|
||||
begin
|
||||
l := Gtk_LABEL(d);
|
||||
inc(counter);
|
||||
nt := Pchar('You clicked me ' + inttostr(counter) + ' times');
|
||||
Gtk_label_set_text(l, nt);
|
||||
end;
|
||||
|
||||
var
|
||||
win: PGtkWindow;
|
||||
button: PGtkButton;
|
||||
Mylabel: PGtkLabel;
|
||||
vbox: PGtkVBox;
|
||||
|
||||
begin
|
||||
Gtk_init(@argc, @argv);
|
||||
win := PGtkWindow(Gtk_window_new(Gtk_WINDOW_TOPLEVEL));
|
||||
Gtk_window_set_title(win, clickme);
|
||||
button := PGtkButton(Gtk_button_new_with_label(clickme));
|
||||
Mylabel := PGtkLabel(Gtk_label_new('There have been no clicks yet'));
|
||||
Gtk_label_set_single_line_mode(Mylabel, TRUE);
|
||||
vbox := PGtkVBox(Gtk_vbox_new(TRUE, 1));
|
||||
Gtk_container_add(Gtk_CONTAINER(vbox), Gtk_WIDGET(Mylabel));
|
||||
Gtk_container_add(Gtk_CONTAINER(vbox), Gtk_WIDGET(button));
|
||||
Gtk_container_add(Gtk_CONTAINER(win), Gtk_WIDGET(vbox));
|
||||
g_signal_connect(G_OBJECT(win), 'delete-event', TGCallBack(@Gtk_main_quit), NULL);
|
||||
g_signal_connect(G_OBJECT(button), 'clicked', TGCallBack(@clickedme), Mylabel);
|
||||
Gtk_widget_show_all(Gtk_WIDGET(win));
|
||||
Gtk_main();
|
||||
end.
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
use Tk;
|
||||
|
||||
$main = MainWindow->new;
|
||||
$l = $main->Label('-text' => 'There have been no clicks yet.')->pack;
|
||||
$count = 0;
|
||||
$main->Button(
|
||||
-text => ' Click Me ',
|
||||
-command => sub { $l->configure(-text => 'Number of clicks: '.(++$count).'.'); },
|
||||
)->pack;
|
||||
MainLoop();
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
use Gtk '-init';
|
||||
|
||||
# Window.
|
||||
$window = Gtk::Window->new;
|
||||
$window->signal_connect('destroy' => sub { Gtk->main_quit; });
|
||||
|
||||
# VBox.
|
||||
$vbox = Gtk::VBox->new(0, 0);
|
||||
$window->add($vbox);
|
||||
|
||||
# Label.
|
||||
$label = Gtk::Label->new('There have been no clicks yet.');
|
||||
$vbox->add($label);
|
||||
|
||||
# Button.
|
||||
$count = 0;
|
||||
$button = Gtk::Button->new(' Click Me ');
|
||||
$vbox->add($button);
|
||||
$button->signal_connect('clicked', sub {
|
||||
$label->set_text(++$count);
|
||||
});
|
||||
|
||||
# Show.
|
||||
$window->show_all;
|
||||
|
||||
# Main loop.
|
||||
Gtk->main;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
use XUL::Gui;
|
||||
|
||||
display
|
||||
TextBox( id=>'txt', value=>'there have been no clicks yet' ),
|
||||
Button( label=>'click me', oncommand=>sub{
|
||||
$ID{txt}->value = ++$clicks
|
||||
});
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
|
||||
|
||||
(load "@ext.l" "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
|
||||
|
||||
(zero *Count)
|
||||
|
||||
(de start ()
|
||||
(app)
|
||||
(action
|
||||
(html 0 "Clicks" NIL NIL
|
||||
(form NIL
|
||||
(gui '(+Init +TextField) "There have been no clicks yet")
|
||||
(----)
|
||||
(gui '(+JS +Button) "click me"
|
||||
'(set> (field -1)
|
||||
(pack "Clicked " (inc '*Count) " times") ) ) ) ) ) )
|
||||
|
||||
(server 8080 "!start")
|
||||
(wait)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
GTK2.Widget mainwindow,clickcnt,clicker;
|
||||
int clicks;
|
||||
|
||||
void click()
|
||||
{
|
||||
clickcnt->set_text("Clicks: "+(++clicks));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
GTK2.setup_gtk();
|
||||
mainwindow=GTK2.Window(GTK2.WindowToplevel);
|
||||
mainwindow->set_title("Click counter");
|
||||
mainwindow->add(GTK2.Vbox(0,10)
|
||||
->add(clickcnt=GTK2.Label("There have been no clicks yet"))
|
||||
->add(clicker=GTK2.Button("Click me"))
|
||||
)->show_all();
|
||||
mainwindow->signal_connect("delete_event",lambda() {exit(0);});
|
||||
clicker->signal_connect("clicked",click);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
$count = 0
|
||||
|
||||
New-Window {
|
||||
New-StackPanel {
|
||||
New-TextBlock "There have been no clicks yet" `
|
||||
-On_Loaded {
|
||||
Set-Variable tb $this
|
||||
}
|
||||
New-Button "Click me" `
|
||||
-On_Click {
|
||||
$count++
|
||||
$tb.Text = $count
|
||||
}
|
||||
}
|
||||
} -SizeToContent WidthAndHeight -Show
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
:- dynamic click/1.
|
||||
|
||||
dialog('Simple windowed application',
|
||||
[ object :=
|
||||
Simple_windowed_application,
|
||||
parts :=
|
||||
[ Simple_windowed_application :=
|
||||
dialog('Simple windowed application'),
|
||||
Name :=
|
||||
label(name, 'There have been no clicks yet'),
|
||||
BtnClick :=
|
||||
button(button)
|
||||
],
|
||||
modifications :=
|
||||
[ BtnClick := [ label := 'Click me !'
|
||||
]
|
||||
],
|
||||
layout :=
|
||||
[ area(Name,
|
||||
area(40, 20, 200, 18)),
|
||||
area(BtnClick,
|
||||
area(90, 60, 80, 24))
|
||||
],
|
||||
behaviour :=
|
||||
[
|
||||
BtnClick := [message := message(@prolog, btnclick, Name)]
|
||||
]
|
||||
]).
|
||||
|
||||
btnclick(Label) :-
|
||||
retract(click(V)),
|
||||
V1 is V+1,
|
||||
assert(click(V1)),
|
||||
sformat(A, '~w click(s)', [V1]),
|
||||
send(Label, selection, A).
|
||||
|
||||
simple_windowed :-
|
||||
retractall(click(_)),
|
||||
assert(click(0)),
|
||||
make_dialog(D, 'Simple windowed application'),
|
||||
send(D, open).
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
Global Window_0
|
||||
Global Window_0_Text_0
|
||||
Global Window_0_Button_1
|
||||
Global Clicks, txt$
|
||||
|
||||
Procedure OpenWindow_Window_0()
|
||||
Protected flags=#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_WindowCentered
|
||||
Window_0 = OpenWindow(#PB_Any, 408, 104, 280, 45, "Simple windowed application", flags)
|
||||
If Window_0
|
||||
SmartWindowRefresh(Window_0, #True)
|
||||
Window_0_Text_0 = TextGadget(#PB_Any, 5, 5, 165, 20, "There have been no clicks yet")
|
||||
Window_0_Button_1 = ButtonGadget(#PB_Any, 190, 10, 85, 30, "Click me")
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
OpenWindow_Window_0()
|
||||
|
||||
Repeat
|
||||
Select WaitWindowEvent()
|
||||
Case #PB_Event_Gadget
|
||||
Select EventGadget()
|
||||
Case Window_0_Text_0
|
||||
Case Window_0_Button_1
|
||||
Clicks+1
|
||||
txt$="You Clicked "+Str(Clicks)+" time"
|
||||
If Clicks>1: txt$+"s": EndIf
|
||||
SetGadgetText(Window_0_Text_0,txt$)
|
||||
EndSelect
|
||||
Case #PB_Event_CloseWindow
|
||||
End
|
||||
EndSelect
|
||||
ForEver
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
from Tkinter import Tk, Label, Button
|
||||
|
||||
def update_label():
|
||||
global n
|
||||
n += 1
|
||||
l["text"] = "Number of clicks: %d" % n
|
||||
|
||||
w = Tk()
|
||||
n = 0
|
||||
l = Label(w, text="There have been no clicks yet")
|
||||
l.pack()
|
||||
Button(w, text="click me", command=update_label).pack()
|
||||
w.mainloop()
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
from Tkinter import Button, Frame, Label, Pack
|
||||
|
||||
class ClickCounter(Frame):
|
||||
def click(self):
|
||||
self.count += 1
|
||||
self.label['text'] = 'Number of clicks: %d' % self.count
|
||||
|
||||
def createWidgets(self):
|
||||
self.label = Label(self, text='here have been no clicks yet')
|
||||
self.label.pack()
|
||||
self.button = Button(self, text='click me', command=self.click)
|
||||
self.button.pack()
|
||||
|
||||
def __init__(self, master=None):
|
||||
Frame.__init__(self, master)
|
||||
Pack.config(self)
|
||||
self.createWidgets()
|
||||
self.count = 0
|
||||
|
||||
if __name__=="__main__":
|
||||
ClickCounter().mainloop()
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import sys
|
||||
from qt import *
|
||||
|
||||
def update_label():
|
||||
global i
|
||||
i += 1
|
||||
lbl.setText("Number of clicks: %i" % i)
|
||||
|
||||
i = 0
|
||||
app = QApplication(sys.argv)
|
||||
win = QWidget()
|
||||
win.resize(200, 100)
|
||||
lbl = QLabel("There have been no clicks yet", win)
|
||||
lbl.setGeometry(0, 15, 200, 25)
|
||||
btn = QPushButton("click me", win)
|
||||
btn.setGeometry(50, 50, 100, 25)
|
||||
btn.connect(btn, SIGNAL("clicked()"), update_label)
|
||||
win.show()
|
||||
app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
|
||||
app.exec_loop()
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import wx
|
||||
|
||||
class MyApp(wx.App):
|
||||
def click(self, event):
|
||||
self.count += 1
|
||||
self.label.SetLabel("Count: %d" % self.count)
|
||||
|
||||
def OnInit(self):
|
||||
frame = wx.Frame(None, wx.ID_ANY, "Hello from wxPython")
|
||||
self.count = 0
|
||||
self.button = wx.Button(frame, wx.ID_ANY, "Click me!")
|
||||
self.label = wx.StaticText(frame, wx.ID_ANY, "Count: 0")
|
||||
self.Bind(wx.EVT_BUTTON, self.click, self.button)
|
||||
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.sizer.Add(self.button, True, wx.EXPAND)
|
||||
self.sizer.Add(self.label, True, wx.EXPAND)
|
||||
frame.SetSizer(self.sizer)
|
||||
frame.SetAutoLayout(True)
|
||||
self.sizer.Fit(frame)
|
||||
|
||||
frame.Show(True)
|
||||
|
||||
self.SetTopWindow(frame)
|
||||
return True
|
||||
|
||||
app = MyApp(0)
|
||||
app.MainLoop()
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
library(gWidgets)
|
||||
library(gWidgetstcltk)
|
||||
win <- gwindow()
|
||||
lab <- glabel("There have been no clicks yet", container=win)
|
||||
btn <- gbutton("click me", container=win, handle=function(h, ...)
|
||||
{
|
||||
val <- as.numeric(svalue(lab))
|
||||
svalue(lab) <- ifelse(is.na(val) ,"1", as.character(val + 1))
|
||||
}
|
||||
)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
REBOL [
|
||||
Title: "Simple Windowed Application"
|
||||
Author: oofoe
|
||||
Date: 2009-12-07
|
||||
URL: http://rosettacode.org/wiki/Simple_Windowed_Application
|
||||
]
|
||||
|
||||
clicks: 0
|
||||
|
||||
; Simple GUI's in REBOL can be defined with 'layout', a
|
||||
; special-purpose language (dialect, in REBOL-speak) for specifying
|
||||
; interfaces. In the example below, I describe a gradient background
|
||||
; with a text label and a button. The block in the button section
|
||||
; details what should happen when it's clicked on -- increment the
|
||||
; number of clicks and update the label text.
|
||||
|
||||
; The 'view' function paints the layout on the screen and listens for
|
||||
; events.
|
||||
|
||||
view layout [
|
||||
backdrop effect [gradient 0x1 black coal]
|
||||
|
||||
label: vtext "There have been no clicks yet."
|
||||
|
||||
button maroon "click me" [
|
||||
clicks: clicks + 1
|
||||
set-face label reform ["clicks:" clicks]
|
||||
]
|
||||
]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#lang racket/gui
|
||||
|
||||
(define frame (new frame% [label "There have been no clicks yet"]))
|
||||
|
||||
(define num-clicks 0)
|
||||
(define (cb obj me)
|
||||
(set! num-clicks (add1 num-clicks))
|
||||
(send frame set-label (format "~a" num-clicks)))
|
||||
|
||||
(new button% [parent frame] [label "Click me"] [callback cb])
|
||||
(send frame show #t)
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
DECLARE SUB buttonClick
|
||||
|
||||
CREATE form AS QForm
|
||||
Center
|
||||
Height = 120
|
||||
Width = 300
|
||||
|
||||
CREATE text AS QLabel
|
||||
Caption = "There have been no clicks yet."
|
||||
Left = 30: Top = 20
|
||||
END CREATE
|
||||
|
||||
CREATE button1 AS QButton
|
||||
Caption = "Click me"
|
||||
Left = 100: Top = 50: Height = 25: Width = 100
|
||||
OnClick = buttonClick
|
||||
END CREATE
|
||||
END CREATE
|
||||
|
||||
SUB buttonClick
|
||||
STATIC count AS Integer
|
||||
count = count+1
|
||||
text.Caption = "Clicked " + STR$(count) + " times."
|
||||
END SUB
|
||||
|
||||
form.ShowModal
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
require 'tk'
|
||||
str = TkVariable.new("no clicks yet")
|
||||
count = 0
|
||||
root = TkRoot.new
|
||||
TkLabel.new(root, "textvariable" => str).pack
|
||||
TkButton.new(root) do
|
||||
text "click me"
|
||||
command {str.value = count += 1}
|
||||
pack
|
||||
end
|
||||
Tk.mainloop
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
Shoes.app do
|
||||
stack do
|
||||
@count = 0
|
||||
@label = para "no clicks yet"
|
||||
button "click me" do
|
||||
@count += 1
|
||||
@label.text = "click: #@count"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
msg$ = "There have been no clicks yet"
|
||||
[loop] cls ' clear screen
|
||||
print msg$
|
||||
button #c, "Click Me", [clickMe] 'create a button with handle and goto [tag]
|
||||
wait
|
||||
|
||||
[clickMe]
|
||||
clicks = clicks + 1
|
||||
msg$ = "Button has been clicked ";clicks;" times"
|
||||
goto [loop]
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import scala.swing._
|
||||
import scala.swing.event._
|
||||
import scala.swing.Swing._
|
||||
|
||||
object SimpleApp extends SimpleSwingApplication {
|
||||
def top = new MainFrame {
|
||||
var nClicks = 0
|
||||
|
||||
val button = new Button {
|
||||
text = "click me"
|
||||
}
|
||||
val label = new Label {
|
||||
text = "There have been no clicks yet"
|
||||
}
|
||||
contents = new BorderPanel {
|
||||
layout(button) = BorderPanel.Position.South
|
||||
layout(label) = BorderPanel.Position.Center
|
||||
}
|
||||
|
||||
preferredSize = ((300, 200): Dimension)
|
||||
|
||||
listenTo(button)
|
||||
reactions += {
|
||||
case ButtonClicked(_) =>
|
||||
nClicks += 1
|
||||
label.text = "There have been %d clicks" format nClicks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
|top clickCount lh button|
|
||||
|
||||
clickCount := 0.
|
||||
lh := ValueHolder with:'There have been no clicks yet'.
|
||||
|
||||
top := StandardSystemView label:'Rosetta Simple Window'.
|
||||
top extent:300@100.
|
||||
top add:((Label new labelChannel:lh) origin: 0 @ 10 corner: 1.0 @ 40).
|
||||
top add:((button := Button label:'Eat Me') origin: 10 @ 50 corner: 100 @ 80).
|
||||
|
||||
button action:[
|
||||
clickCount := clickCount + 1.
|
||||
lh value: ('number of clicks: %1' bindWith:clickCount)
|
||||
].
|
||||
|
||||
top open
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
Prgm
|
||||
Local clicks
|
||||
0 → clicks
|
||||
1 → ok © System variable also set by Dialog statement
|
||||
While ok = 1
|
||||
Dialog
|
||||
Title "Rosetta Code"
|
||||
Text "There have been " & string(clicks) & " OKs"
|
||||
EndDlog
|
||||
clicks + 1 → clicks
|
||||
EndWhile
|
||||
EndPrgm
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package require Tk
|
||||
pack [label .l -text "There have been no clicks yet"]
|
||||
set count 0
|
||||
pack [button .b -text "click me" -command upd]
|
||||
proc upd {} {
|
||||
.l configure -text "Number of clicks: [incr ::count]"
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
import gui
|
||||
$include "guih.icn"
|
||||
|
||||
class SimpleApp : Dialog (label)
|
||||
|
||||
# -- automatically called when the dialog is created
|
||||
method component_setup()
|
||||
# create and add the label
|
||||
label := Label("label=There have been no clicks yet","pos=50%,33%", "align=c,c")
|
||||
add (label)
|
||||
|
||||
# create and add the button
|
||||
button := TextButton("label=Click me", "pos=50%,66%", "align=c,c")
|
||||
button.connect(self, "clicked", ACTION_EVENT)
|
||||
add (button)
|
||||
|
||||
# some cosmetic settings for the window
|
||||
attrib("size=180,70", "bg=light gray")
|
||||
end
|
||||
|
||||
method clicked ()
|
||||
static count := 0
|
||||
count +:= 1
|
||||
label.set_label ("Clicked " || count || " times")
|
||||
end
|
||||
end
|
||||
|
||||
procedure main()
|
||||
local d := SimpleApp ()
|
||||
d.show_modal()
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Reg_Set(10, "There have been no clicks yet")
|
||||
#1 = 0
|
||||
repeat (ALL) {
|
||||
#2 = Dialog_Input_1(3, "`Simple Windowed Application`,
|
||||
`|@(10)`,
|
||||
`[&Click me]`,`[&Exit]`",
|
||||
APP+CENTER, 0, 0)
|
||||
if (#2 != 1) { break } // ESC or Exit
|
||||
#1++
|
||||
Num_Str(#1, 10)
|
||||
Reg_Set(10, "Clicked", INSERT)
|
||||
Reg_Set(10, " times", APPEND)
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
VERSION 5.00
|
||||
Begin VB.Form Form2
|
||||
Caption = "There have been no clicks yet"
|
||||
ClientHeight = 2940
|
||||
ClientLeft = 60
|
||||
ClientTop = 600
|
||||
ClientWidth = 8340
|
||||
LinkTopic = "Form1"
|
||||
ScaleHeight = 2940
|
||||
ScaleWidth = 8340
|
||||
StartUpPosition = 3 'Windows Default
|
||||
Begin VB.CommandButton Command1
|
||||
Caption = "Click me!"
|
||||
Height = 495
|
||||
Left = 3600
|
||||
TabIndex = 0
|
||||
Top = 1200
|
||||
Width = 1215
|
||||
End
|
||||
End
|
||||
Attribute VB_Name = "Form1"
|
||||
Attribute VB_GlobalNameSpace = False
|
||||
Attribute VB_Creatable = False
|
||||
Attribute VB_PredeclaredId = True
|
||||
Attribute VB_Exposed = False
|
||||
'-----user-written code begins here; everything above this line is hidden in the GUI-----
|
||||
Private clicked As Long
|
||||
|
||||
Private Sub Command1_Click()
|
||||
clicked = clicked + 1
|
||||
Me.Caption = clicked & " clicks."
|
||||
End Sub
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
include c:\cxpl\stdlib; \standard library provides mouse routines, etc.
|
||||
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
|
||||
int Clicks, Mx, My; \number of clicks and mouse coordinates
|
||||
|
||||
[ShowCursor(false); \turn off flashing cursor
|
||||
Attrib($1F); \bright white characters on blue
|
||||
SetWind(Wx, Wy, Wx+Ww, Wy+Wh, 2, true); \blue window with no scroll
|
||||
DrawBox(Wx, Wy, Wx+Ww, Wy+Wh, 3); \draw borders
|
||||
Cursor(Wx+5, Wy+3); Text(6, "There have been no clicks yet.");
|
||||
DrawBox(Bx, By, Bx+Bw, By+Bh, 0); \draw button
|
||||
Cursor(Bx+2, By+2); Text(6, "Click me");
|
||||
|
||||
OpenMouse;
|
||||
ShowMouse(true);
|
||||
Clicks:= 0;
|
||||
repeat if GetMouseButton(0) then \left button down
|
||||
[while GetMouseButton(0) do []; \wait for release
|
||||
Mx:= GetMousePosition(0) / 8; \character coordinates
|
||||
My:= GetMousePosition(1) / 8;
|
||||
if Mx>=Bx & Mx<=Bx+Bw & My>=By & My<=By+Bh then
|
||||
[Clicks:= Clicks+1; \mouse pointer is on the button
|
||||
Cursor(Wx+4, Wy+3);
|
||||
Text(6, "Times button has been clicked: ");
|
||||
IntOut(6, Clicks);
|
||||
];
|
||||
];
|
||||
until ChkKey; \keystroke terminates program
|
||||
SetVid(3); \turn off mouse and turn on flashing cursor
|
||||
]
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#include "button.i"
|
||||
|
||||
window, 0;
|
||||
btn_click = Button(text="click me", x=.395, y=.65, dx=0.04368, dy=0.0091);
|
||||
btn_quit = Button(text="quit", x=.395, y=.6, dx=0.02184, dy=0.0091);
|
||||
count = 0;
|
||||
msg = "There have been no clicks yet";
|
||||
finished = 0;
|
||||
do {
|
||||
fma;
|
||||
plt, msg, .395, .7, justify="CH";
|
||||
button_plot, btn_click;
|
||||
button_plot, btn_quit;
|
||||
xy = mouse(0, 0, "");
|
||||
if(button_test(btn_click, xy(1), xy(2))) {
|
||||
count++;
|
||||
msg = swrite(format="Number of clicks: %d", count);
|
||||
} else if(button_test(btn_quit, xy(1), xy(2))) {
|
||||
finished = 1;
|
||||
winkill, 0;
|
||||
}
|
||||
} while(!finished);
|
||||
Loading…
Add table
Add a link
Reference in a new issue