June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,27 @@
|
|||
USING: accessors arrays kernel math math.parser namespaces
|
||||
sequences ui ui.gadgets ui.gadgets.borders ui.gadgets.buttons
|
||||
ui.gadgets.grids ui.gadgets.labels ui.gadgets.worlds ;
|
||||
IN: rosetta-code.simple-windowed-application
|
||||
|
||||
SYMBOL: n
|
||||
|
||||
CONSTANT: on-btn-press [
|
||||
parents second n get number>string <label> { 0 1 }
|
||||
grid-add drop n inc
|
||||
]
|
||||
|
||||
: build-ui ( -- ) [
|
||||
f
|
||||
T{ world-attributes { title "Simple windowed application" } }
|
||||
clone
|
||||
"click me" on-btn-press <border-button> 1array
|
||||
"There have been no clicks yet" <label> 1array
|
||||
2array <grid>
|
||||
{ 100 100 } <border>
|
||||
>>gadgets
|
||||
open-window
|
||||
] with-ui ;
|
||||
|
||||
: main ( -- ) 1 n set build-ui ;
|
||||
|
||||
MAIN: main
|
||||
|
|
@ -1,35 +1,38 @@
|
|||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
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{
|
||||
import javax.swing.SwingUtilities;
|
||||
public class Clicks extends JFrame{
|
||||
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
|
||||
super("Clicks");//set window title
|
||||
JLabel label = new JLabel("There have been no clicks yet");
|
||||
JButton clicker = new JButton("click me");
|
||||
clicker.addActionListener(//listen to the button
|
||||
new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
label.setText("There have been " + (++clicks) + " clicks");//change the text
|
||||
}
|
||||
}
|
||||
);
|
||||
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
|
||||
label.setPreferredSize(new Dimension(300,100));//nice big label
|
||||
label.setHorizontalAlignment(JLabel.CENTER);//text not up against the side
|
||||
pack();//fix layout
|
||||
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
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater( //Swing UI updates should not happen on the main thread
|
||||
() -> new Clicks() //call the constructor where all the magic happens
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
using Gtk.ShortNames
|
||||
|
||||
|
||||
function clickwindow()
|
||||
clicks = 0
|
||||
win = Window("Click Counter", 300, 100) |> (Frame() |> (vbox = Box(:v)))
|
||||
lab = Label("There have been no clicks yet.")
|
||||
but = Button("click me")
|
||||
push!(vbox, lab)
|
||||
push!(vbox, but)
|
||||
setproperty!(vbox, :expand, lab, true)
|
||||
setproperty!(vbox, :spacing, 20)
|
||||
callback(w) = (clicks += 1; setproperty!(lab, :label, "There have been $clicks button clicks."))
|
||||
id = signal_connect(callback, but, "clicked")
|
||||
c = Condition()
|
||||
endit(w) = notify(c)
|
||||
signal_connect(endit, win, :destroy)
|
||||
showall(win)
|
||||
wait(c)
|
||||
end
|
||||
|
||||
|
||||
clickwindow()
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import tornadofx.*
|
||||
|
||||
class ClicksView: View("Clicks example") {
|
||||
var clicks = 0
|
||||
override val root = vbox(5) {
|
||||
var label1 = label("There have been no clicks yet")
|
||||
button("Click me!") { action { label1.text = "Clicked ${++clicks} times." } }
|
||||
}
|
||||
}
|
||||
|
||||
class ClicksApp: App(ClicksView::class)
|
||||
|
||||
fun main(args: Array<String>) = launch<ClicksApp>(args)
|
||||
|
|
@ -1,17 +1,18 @@
|
|||
use GTK::Simple;
|
||||
use GTK::Simple::App;
|
||||
|
||||
my GTK::Simple::App $app .= new(title => 'Simple Windowed Application');
|
||||
|
||||
$app.size_request(350, 100);
|
||||
$app.size-request(350, 100);
|
||||
|
||||
$app.set_content(
|
||||
$app.set-content(
|
||||
GTK::Simple::VBox.new(
|
||||
my $label = GTK::Simple::Label.new( text => 'There have been no clicks yet'),
|
||||
my $button = GTK::Simple::Button.new(label => 'click me'),
|
||||
)
|
||||
);
|
||||
|
||||
$app.border_width = 40;
|
||||
$app.border-width = 40;
|
||||
|
||||
$button.clicked.tap: {
|
||||
state $clicks += 1;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
include pGUI.e
|
||||
|
||||
Ihandle dlg, lbl, btn, vbox
|
||||
integer clicks = 0
|
||||
|
||||
function click_cb(Ihandle /*btn*/)
|
||||
clicks += 1
|
||||
IupSetStrAttribute(lbl,"TITLE","clicked %d times",{clicks})
|
||||
return IUP_DEFAULT;
|
||||
end function
|
||||
|
||||
IupOpen()
|
||||
lbl = IupLabel("There have been no clicks yet")
|
||||
btn = IupButton("Click me", Icallback("click_cb"))
|
||||
vbox = IupVbox({lbl, IupHbox({IupFill(),btn,IupFill()})})
|
||||
dlg = IupDialog(vbox,"MARGIN=10x10, GAP=10, RASTERSIZE=400x0")
|
||||
IupSetAttribute(dlg, "TITLE", "Simple windowed application")
|
||||
IupShow(dlg)
|
||||
IupMainLoop()
|
||||
IupClose()
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
include arwen.ew
|
||||
|
||||
constant main = create(Window,"myApp",0,0,100,100,300,200, 0)
|
||||
constant main = create(Window,"Simple windowed application",0,0,100,100,300,200, 0)
|
||||
constant label = create(Label, "There have been no clicks yet",0,main,10,10,250,30,0)
|
||||
constant btn = create(Button,"Click me",0,main,100,50,100,30,0)
|
||||
integer count = 0
|
||||
|
||||
function mainHandler(integer id, integer msg, atom wParam, object lParam)
|
||||
without warning
|
||||
function mainHandler(integer id, integer msg, atom /*wParam*/, object /*lParam*/)
|
||||
if id=btn and msg=WM_COMMAND then
|
||||
count += 1
|
||||
setText(label,sprintf("clicked %d times",count))
|
||||
Loading…
Add table
Add a link
Reference in a new issue