Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,2 @@
|
|||
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.
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
category:
|
||||
- Basic language learning
|
||||
- Simple
|
||||
note: GUI
|
||||
requires:
|
||||
- Graphics
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
import gui
|
||||
$include "guih.icn"
|
||||
|
||||
procedure main()
|
||||
SimpleWindow().show_modal()
|
||||
end
|
||||
|
||||
class SimpleWindow : Dialog(label, button, count)
|
||||
method component_setup()
|
||||
self.set_attribs("size=222,139")
|
||||
label := Label()
|
||||
label.set_pos("24", "24")
|
||||
label.set_internal_alignment("l")
|
||||
label.set_label("There have been no clicks yet.")
|
||||
self.add(label)
|
||||
button := TextButton()
|
||||
button.set_pos(24, 53)
|
||||
button.set_label("click me")
|
||||
button.set_internal_alignment("c")
|
||||
button.connect(self, "incr", ACTION_EVENT)
|
||||
self.add(button)
|
||||
end
|
||||
|
||||
method incr()
|
||||
/count := 0
|
||||
label.set_label("There have been "||(count+:=1)||" clicks.")
|
||||
end
|
||||
|
||||
initially
|
||||
self.Dialog.initially()
|
||||
end
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
SIMPLEAPP=: noun define
|
||||
pc simpleApp;
|
||||
cc inc button;cn "Click me";
|
||||
cc shownText static;cn "There have been no clicks yet.";
|
||||
)
|
||||
|
||||
simpleApp_run=: verb define
|
||||
wd SIMPLEAPP
|
||||
simpleApp_accum=: 0 NB. initialize accumulator
|
||||
wd 'pshow;'
|
||||
)
|
||||
|
||||
simpleApp_inc_button=: verb define
|
||||
wd 'set shownText text ','Button-use count: ',": simpleApp_accum=: >: simpleApp_accum
|
||||
)
|
||||
|
||||
simpleApp_close=: wd bind 'pclose'
|
||||
simpleApp_cancel=: simpleApp_close
|
||||
|
||||
simpleApp_run''
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
use GTK::Simple;
|
||||
|
||||
my GTK::Simple::App $app .= new(title => 'Simple Windowed Application');
|
||||
|
||||
$app.size_request(350, 100);
|
||||
|
||||
$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;
|
||||
|
||||
$button.clicked.tap: {
|
||||
state $clicks += 1;
|
||||
$label.text = "There has been $clicks click{ 's' if $clicks != 1 }";
|
||||
}
|
||||
|
||||
$app.run;
|
||||
|
|
@ -1,29 +1,22 @@
|
|||
import scala.swing._
|
||||
import scala.swing.event._
|
||||
import scala.swing.Swing._
|
||||
import scala.swing.{ BorderPanel, Button, Label, MainFrame, SimpleSwingApplication }
|
||||
import scala.swing.event.ButtonClicked
|
||||
|
||||
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 {
|
||||
var nClicks = 0
|
||||
|
||||
val (button, label) = (new Button { text = "click me" },
|
||||
new Label { text = "There have been no clicks yet" })
|
||||
|
||||
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
|
||||
listenTo(button)
|
||||
reactions += {
|
||||
case ButtonClicked(_) =>
|
||||
nClicks += 1
|
||||
label.text = s"There have been ${nClicks} clicks"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue