<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[Curl Global Community - Try 2: Making a Simple Action Game]]></title>
		<link>https://communities.curl.com/</link>
		<description><![CDATA[Curl Global Community - https://communities.curl.com]]></description>
		<pubDate>Wed, 06 May 2026 16:13:15 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Page 8: Extra Practice]]></title>
			<link>https://communities.curl.com/showthread.php?tid=54</link>
			<pubDate>Thu, 16 Jun 2011 07:05:26 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=54</guid>
			<description><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Extra Practice</span></span></span><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Practice Problem 1: Basics</span></span></span><br />
<br />
Let’s create a program that uses a <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">CommandButton</span></span> to change the color of a <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">Frame</span></span>.<br />
<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_19.png" /><br />
<br />
Hint: Give a name to the Frame, and then set the background option in the event handler.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Solution</span></span></span><br />
<br />
Solution Program: <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try1\04_exercise1\start.curl</span> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value<br />
&nbsp;&nbsp;&nbsp;&nbsp;let f:Frame = {Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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= 5pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;halign = center,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{HBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;red-button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;blue-button<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Practice Problem 2: Application</span></span></span><br />
<br />
Let’s add a reset button (reset-btn) to the above solution. Set the initial state of <span style="font-family: Courier;" class="mycode_font">start-btn</span> to invalid, and then add the following processing depending on which of the following three buttons are pressed.<br />
<br />
<span style="font-family: Courier;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">start-btn</span></span><ul class="mycode_list"><li>Disable <span style="font-family: Courier;" class="mycode_font">start-btn</span><br />
</li>
<li>Enable <span style="font-family: Courier;" class="mycode_font">stop-btn</span><br />
</li>
</ul>
<br />
<span style="font-family: Courier;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">stop-btn</span></span><ul class="mycode_list"><li>Enable <span style="font-family: Courier;" class="mycode_font">start-btn</span><br />
</li>
<li>Disable <span style="font-family: Courier;" class="mycode_font">stop-btn</span><br />
</li>
</ul>
<br />
<span style="font-family: Courier;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">reset-btn</span></span><ul class="mycode_list"><li>Reset <span style="font-family: Courier;" class="mycode_font">start-time</span> to <span style="font-family: Courier;" class="mycode_font">null</span><br />
</li>
<li>Enable <span style="font-family: Courier;" class="mycode_font">start-btn</span><br />
</li>
<li>Disable <span style="font-family: Courier;" class="mycode_font">stop-btn</span><br />
</li>
</ul>
<img src="wiki/easy-ide-book/try2/images/figure_2_20.png" /><br />
<br />
Hint: Use the enabled? option to switch buttons between enabled and disabled.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Solution</span></span></span><br />
<br />
Solution Program: c:\Curl\Try1\05_exercise2\start.curl<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-time:#DateTime<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-btn:CommandButton = {CommandButton label = Start}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let stop-btn:CommandButton = {CommandButton label = Stop, enabled? = false}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let reset-btn:CommandButton = {CommandButton label = Reset}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{start-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = {DateTime}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-btn.enabled? = false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set stop-btn.enabled? = true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{stop-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-btn.enabled? = true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set stop-btn.enabled? = false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let elapsed-time:Time = {start-time.elapsed}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let time-double:double = elapsed-time / 1s<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let score:int = {switch time-double using &lt;=<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 10 do (time-double * 10) asa int<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 20 do {abs ((20 - time-double) * 10) asa int}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message {VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center font-size = 20pt, {value score} points!!},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center {value {start-time.elapsed}}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{reset-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = null<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-btn.enabled? = true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set stop-btn.enabled? = false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;halign = center,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{bold Try to stop in 10 seconds},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stop-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reset-btn<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>]]></description>
			<content:encoded><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Extra Practice</span></span></span><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Practice Problem 1: Basics</span></span></span><br />
<br />
Let’s create a program that uses a <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">CommandButton</span></span> to change the color of a <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">Frame</span></span>.<br />
<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_19.png" /><br />
<br />
Hint: Give a name to the Frame, and then set the background option in the event handler.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Solution</span></span></span><br />
<br />
Solution Program: <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try1\04_exercise1\start.curl</span> <br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value<br />
&nbsp;&nbsp;&nbsp;&nbsp;let f:Frame = {Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background = yellow,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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Box<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;red-button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;blue-button<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Practice Problem 2: Application</span></span></span><br />
<br />
Let’s add a reset button (reset-btn) to the above solution. Set the initial state of <span style="font-family: Courier;" class="mycode_font">start-btn</span> to invalid, and then add the following processing depending on which of the following three buttons are pressed.<br />
<br />
<span style="font-family: Courier;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">start-btn</span></span><ul class="mycode_list"><li>Disable <span style="font-family: Courier;" class="mycode_font">start-btn</span><br />
</li>
<li>Enable <span style="font-family: Courier;" class="mycode_font">stop-btn</span><br />
</li>
</ul>
<br />
<span style="font-family: Courier;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">stop-btn</span></span><ul class="mycode_list"><li>Enable <span style="font-family: Courier;" class="mycode_font">start-btn</span><br />
</li>
<li>Disable <span style="font-family: Courier;" class="mycode_font">stop-btn</span><br />
</li>
</ul>
<br />
<span style="font-family: Courier;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">reset-btn</span></span><ul class="mycode_list"><li>Reset <span style="font-family: Courier;" class="mycode_font">start-time</span> to <span style="font-family: Courier;" class="mycode_font">null</span><br />
</li>
<li>Enable <span style="font-family: Courier;" class="mycode_font">start-btn</span><br />
</li>
<li>Disable <span style="font-family: Courier;" class="mycode_font">stop-btn</span><br />
</li>
</ul>
<img src="wiki/easy-ide-book/try2/images/figure_2_20.png" /><br />
<br />
Hint: Use the enabled? option to switch buttons between enabled and disabled.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Solution</span></span></span><br />
<br />
Solution Program: c:\Curl\Try1\05_exercise2\start.curl<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-time:#DateTime<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-btn:CommandButton = {CommandButton label = Start}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let stop-btn:CommandButton = {CommandButton label = Stop, enabled? = false}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let reset-btn:CommandButton = {CommandButton label = Reset}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{start-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = {DateTime}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-btn.enabled? = false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set stop-btn.enabled? = true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{stop-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-btn.enabled? = true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set stop-btn.enabled? = false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let elapsed-time:Time = {start-time.elapsed}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let time-double:double = elapsed-time / 1s<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let score:int = {switch time-double using &lt;=<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 10 do (time-double * 10) asa int<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 20 do {abs ((20 - time-double) * 10) asa int}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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bsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{reset-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = null<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-btn.enabled? = true<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set stop-btn.enabled? = false<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;halign = center,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{bold Try to stop in 10 seconds},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stop-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reset-btn<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Page 7: Summary]]></title>
			<link>https://communities.curl.com/showthread.php?tid=53</link>
			<pubDate>Thu, 16 Jun 2011 06:57:49 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=53</guid>
			<description><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">TRY 2 Overview</span></span></span><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event handler structure</span></span></span><br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">on</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on event-type do body}<br />
{on event-type at target-var[:target-type] do body}<br />
{on event-var:event-type at target-var[:target-type] do body}</code></div></div><br />
where <ul class="mycode_list"><li>event-var:event-type: binds a variable to the event.<br />
</li>
<li>target-var[:target-type]: binds a variable to the target.<br />
</li>
<li>body is the code for the event handler procedure.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Branching expressions</span></span></span><br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">if</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition-1 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
 elseif condition-2 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
 elseif condition-3 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-3 <br />
&nbsp;&nbsp;&nbsp;&nbsp;... <br />
 elseif condition-n then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
 [else <br />
&nbsp;&nbsp;&nbsp;&nbsp; code-block-n+1] <br />
}</code></div></div><br />
where<ul class="mycode_list"><li><span style="font-family: Courier;" class="mycode_font">condition-1, condition-2, ...</span>: are Boolean expressions.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">code-block-1, code-block-2, ...</span>: each consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">switch</span></span></span><br />
<br />
The <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expression has the following syntax:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{switch compare-expr [using compare-operator] <br />
&nbsp;&nbsp;&nbsp;&nbsp; case value-1 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
&nbsp;&nbsp;&nbsp;&nbsp; case value-2 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... <br />
&nbsp;&nbsp;&nbsp;&nbsp; case value-n do <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[else code-block-n+1] <br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div> <br />
<br />
where<ul class="mycode_list"><li><span style="font-family: Courier;" class="mycode_font">compare-expr, value-1, value-2, value-n</span>: are Curl language expressions. These expressions can evaluate to any Curl language type.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">compare-operator</span>: the operator that the Curl language uses when comparing compare-expr to value-1, value-2, and so on.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">code-block-1, code-block-2, code-block-n</span>: consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Types of graphical containers</span></span></span><br />
<img src="attachment.php?aid=97" /><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=97" target="_blank" title="">2-4.PNG</a> (Size: 13.48 KB / Downloads: 1308)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">TRY 2 Overview</span></span></span><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event handler structure</span></span></span><br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">on</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on event-type do body}<br />
{on event-type at target-var[:target-type] do body}<br />
{on event-var:event-type at target-var[:target-type] do body}</code></div></div><br />
where <ul class="mycode_list"><li>event-var:event-type: binds a variable to the event.<br />
</li>
<li>target-var[:target-type]: binds a variable to the target.<br />
</li>
<li>body is the code for the event handler procedure.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Branching expressions</span></span></span><br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">if</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition-1 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
 elseif condition-2 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
 elseif condition-3 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-3 <br />
&nbsp;&nbsp;&nbsp;&nbsp;... <br />
 elseif condition-n then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
 [else <br />
&nbsp;&nbsp;&nbsp;&nbsp; code-block-n+1] <br />
}</code></div></div><br />
where<ul class="mycode_list"><li><span style="font-family: Courier;" class="mycode_font">condition-1, condition-2, ...</span>: are Boolean expressions.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">code-block-1, code-block-2, ...</span>: each consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">switch</span></span></span><br />
<br />
The <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expression has the following syntax:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{switch compare-expr [using compare-operator] <br />
&nbsp;&nbsp;&nbsp;&nbsp; case value-1 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
&nbsp;&nbsp;&nbsp;&nbsp; case value-2 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... <br />
&nbsp;&nbsp;&nbsp;&nbsp; case value-n do <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[else code-block-n+1] <br />
&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div> <br />
<br />
where<ul class="mycode_list"><li><span style="font-family: Courier;" class="mycode_font">compare-expr, value-1, value-2, value-n</span>: are Curl language expressions. These expressions can evaluate to any Curl language type.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">compare-operator</span>: the operator that the Curl language uses when comparing compare-expr to value-1, value-2, and so on.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">code-block-1, code-block-2, code-block-n</span>: consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Types of graphical containers</span></span></span><br />
<img src="attachment.php?aid=97" /><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=97" target="_blank" title="">2-4.PNG</a> (Size: 13.48 KB / Downloads: 1308)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Page 6: Let’s look at the make-up of this game]]></title>
			<link>https://communities.curl.com/showthread.php?tid=52</link>
			<pubDate>Thu, 16 Jun 2011 06:50:06 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=52</guid>
			<description><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Let’s look at the make-up of this game</span></span></span><br />
<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_17.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">1. 'let' variable declaration and 'DateTime' date operation</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let start-time:#DateTime</code></div></div><br />
The above declares the variables that are used by the program. The <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">DateTime</span></span> class is used for date or time-related operations. The program will use this variable to save the time at which the start button is pressed. Pay close attention to the variable declaration.<br />
<br />
For the variables that we have seen so far, the declaration has taken this format: <br />
<br />
<span style="font-family: Courier;" class="mycode_font">let variable_name:type_name = initial_value.</span><br />
<br />
We can, however, omit the <span style="font-family: Courier;" class="mycode_font">= initial_value</span> part. When the type is <span style="font-family: Courier;" class="mycode_font">int</span>, omitting the initial value results in the variable being set to 0. We refer to int and bool as “primitive” types. Whenever we omit the initial value for variables of these types, a standard default value is used.<br />
<br />
In our example, if we don’t specify an initial value, the variable is set to a value that we call <span style="font-family: Courier;" class="mycode_font">null</span>. To declare that <span style="font-family: Courier;" class="mycode_font">null </span>can be substituted for a variable, we have to prefix the type name with <span style="font-family: Courier;" class="mycode_font">#</span> as in <span style="font-family: Courier;" class="mycode_font">#DateTime.</span><br />
<br />
<hr class="mycode_hr" />
<br />
<br />
<img src="wiki/easy-ide-book/common/images/point.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">null</span></span></span><br />
<br />
<span style="font-family: Courier;" class="mycode_font">null</span> indicates that, at this instant, this variable does not refer to any object. <br />
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. add-event-handler method: start-btn</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{start-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = {DateTime}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
In previous examples, event handlers have been added immediately after an object is created. In this example, we did not add the event handler when we create the <span style="font-family: Courier;" class="mycode_font">CommandButton</span>. Instead, we used the <span style="font-family: Courier;" class="mycode_font">add-event-handler</span> method to add the event handler later. By adding a variable name, we can use that name to add an event handler later.<br />
<br />
In our example here, pressing the 'Start' button causes the current time to be set as the value for the <span style="font-family: Courier;" class="mycode_font">start-time</span> variable.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. add-event-handler method: stop-btn</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{stop-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
In the same way as in (2), an event handler is also added to <span style="font-family: Courier;" class="mycode_font">stop-btn</span>. The event handler performs the following processing. <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>[list]<br />
[*](3)-1&nbsp;&nbsp; Acquires the length of time that elapses after start-btn is pressed.<br />
[*](3)-2&nbsp;&nbsp; Determines a score based on the elapsed time.<br />
[*](3)-3&nbsp;&nbsp; Displays a message<br />
[/list]<br />
Below, we’ll look at these in order.<br />
<br />
[size=large][font=Arial][b]3-1. Use “elapsed” method to acquire the length of time that elapses after start-btn is pressed.[/b][/font][/size]<br />
<br />
[code]{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;let elapsed-time:Time = {start-time.elapsed}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let time-double:double = elapsed-time / 1s<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
<span style="color: #9400D3;" class="mycode_color">DateTime</span> uses a method called “elapsed” to acquire the length of time since the creation of the DateTime object. That time is given in seconds. A method is a function that defines a behavior of a class.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3-2. Use 'switch' expression to calculate a score.</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let score:int = {switch time-double using &lt;=<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 10 do (time-double * 10) asa int<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 20 do {abs ((20 - time-double) * 10) asa int}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
If we say that exactly 10s is worth a score of 100, a high score will be given for attempts close to 10s. First, the type of the elapsed time data is converted from a time into a real number. Also, at the switch branch, a score is determined. When the elapsed time is within 10s, a score is obtained by multiplying the converted time by 10. When the elapsed time is between 10s and 20s, a score is obtained by subtracting the converted time from 20 and then multiplying the result by 10. For more than 20s, the score is 0.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">if</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition-1 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
 elseif condition-2 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
 elseif condition-3 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-3 <br />
&nbsp;&nbsp;&nbsp;&nbsp;... <br />
 elseif condition-n then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
&nbsp;&nbsp;&nbsp;&nbsp;[else <br />
&nbsp;&nbsp;&nbsp;&nbsp; code-block-n+1] <br />
}</code></div></div><br />
where<ul class="mycode_list"><li>condition-1, condition-2, ...: are Boolean expressions.<br />
</li>
<li>code-block-1, code-block-2, ...: each consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Switch Expression Syntax</span></span></span><br />
<br />
The <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expression has the following syntax:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{switch compare-expr [using compare-operator] <br />
 case value-1 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
 case value-2 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
&nbsp;&nbsp;&nbsp;&nbsp;... <br />
 case value-n do <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
&nbsp;&nbsp;[else code-block-n+1] <br />
}</code></div></div><br />
where<br />
<ul class="mycode_list"><li><span style="font-family: Courier;" class="mycode_font">compare-expr, value-1, value-2, value-n</span>: are Curl language expressions. These expressions can evaluate to any Curl language type.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">compare-operator</span>: is the operator that the Curl language uses when comparing compare-expr to <span style="font-family: Courier;" class="mycode_font">value-1, value-2</span>, and so on. When the comparison operator is omitted, “==” is used.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">code-block-1, code-block-2, code-block-n</span>: consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
Now, let’s consider the usage the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expression. This expression sets the initial value of the variable declared in the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">let</span></span> phrase. <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">if</span></span> and <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expressions that include an else clause can return a value.<br />
<br />
In our example, the values coded after do and else are used to initialize the variable score.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3-3. Displays a message.</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{popup-message {VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center font-size = 20pt, You have {value score} points! ! },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center {value {start-time.elapsed}}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
}</code></div></div><br />
A message containing the score is displayed as a pop-up. <span style="color: #9400D3;" class="mycode_color">popup-message</span> is not limited to displaying character strings, but can also display graphical objects. Here, the <span style="color: #9400D3;" class="mycode_color">VBox</span> graphical container is displayed.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_18.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">4. Creating a screen layout with 'VBox'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;halign = center,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{bold Try to stop in 10 seconds},<br />
&nbsp;&nbsp;&nbsp;&nbsp;start-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;stop-btn<br />
}</code></div></div><br />
If we look at this expression in its entirety, we find that it is enclosed in large <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">value</span></span> expression. This creates a code block. Each <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">value</span></span> expression can itself contain multiple expressions. However, when there are multiple expressions, the result for the final expression is returned and displayed on the screen. For this example, the final expression begins with <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span>.<br />
<br />
<span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span> is a graphical container that is used to arrange objects vertically. The first three lines in this expression specify option values, which specify the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span> margins and the spacing between objects. The expression coded with bold appears in the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span>, along with start-btn and stop-btn. These are arranged vertically.]]></description>
			<content:encoded><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Let’s look at the make-up of this game</span></span></span><br />
<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_17.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">1. 'let' variable declaration and 'DateTime' date operation</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let start-time:#DateTime</code></div></div><br />
The above declares the variables that are used by the program. The <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">DateTime</span></span> class is used for date or time-related operations. The program will use this variable to save the time at which the start button is pressed. Pay close attention to the variable declaration.<br />
<br />
For the variables that we have seen so far, the declaration has taken this format: <br />
<br />
<span style="font-family: Courier;" class="mycode_font">let variable_name:type_name = initial_value.</span><br />
<br />
We can, however, omit the <span style="font-family: Courier;" class="mycode_font">= initial_value</span> part. When the type is <span style="font-family: Courier;" class="mycode_font">int</span>, omitting the initial value results in the variable being set to 0. We refer to int and bool as “primitive” types. Whenever we omit the initial value for variables of these types, a standard default value is used.<br />
<br />
In our example, if we don’t specify an initial value, the variable is set to a value that we call <span style="font-family: Courier;" class="mycode_font">null</span>. To declare that <span style="font-family: Courier;" class="mycode_font">null </span>can be substituted for a variable, we have to prefix the type name with <span style="font-family: Courier;" class="mycode_font">#</span> as in <span style="font-family: Courier;" class="mycode_font">#DateTime.</span><br />
<br />
<hr class="mycode_hr" />
<br />
<br />
<img src="wiki/easy-ide-book/common/images/point.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">null</span></span></span><br />
<br />
<span style="font-family: Courier;" class="mycode_font">null</span> indicates that, at this instant, this variable does not refer to any object. <br />
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. add-event-handler method: start-btn</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{start-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = {DateTime}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
In previous examples, event handlers have been added immediately after an object is created. In this example, we did not add the event handler when we create the <span style="font-family: Courier;" class="mycode_font">CommandButton</span>. Instead, we used the <span style="font-family: Courier;" class="mycode_font">add-event-handler</span> method to add the event handler later. By adding a variable name, we can use that name to add an event handler later.<br />
<br />
In our example here, pressing the 'Start' button causes the current time to be set as the value for the <span style="font-family: Courier;" class="mycode_font">start-time</span> variable.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. add-event-handler method: stop-btn</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{stop-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
In the same way as in (2), an event handler is also added to <span style="font-family: Courier;" class="mycode_font">stop-btn</span>. The event handler performs the following processing. <div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>[list]<br />
[*](3)-1&nbsp;&nbsp; Acquires the length of time that elapses after start-btn is pressed.<br />
[*](3)-2&nbsp;&nbsp; Determines a score based on the elapsed time.<br />
[*](3)-3&nbsp;&nbsp; Displays a message<br />
[/list]<br />
Below, we’ll look at these in order.<br />
<br />
[size=large][font=Arial][b]3-1. Use “elapsed” method to acquire the length of time that elapses after start-btn is pressed.[/b][/font][/size]<br />
<br />
[code]{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;let elapsed-time:Time = {start-time.elapsed}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let time-double:double = elapsed-time / 1s<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
<span style="color: #9400D3;" class="mycode_color">DateTime</span> uses a method called “elapsed” to acquire the length of time since the creation of the DateTime object. That time is given in seconds. A method is a function that defines a behavior of a class.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3-2. Use 'switch' expression to calculate a score.</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>let score:int = {switch time-double using &lt;=<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 10 do (time-double * 10) asa int<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 20 do {abs ((20 - time-double) * 10) asa int}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</code></div></div><br />
If we say that exactly 10s is worth a score of 100, a high score will be given for attempts close to 10s. First, the type of the elapsed time data is converted from a time into a real number. Also, at the switch branch, a score is determined. When the elapsed time is within 10s, a score is obtained by multiplying the converted time by 10. When the elapsed time is between 10s and 20s, a score is obtained by subtracting the converted time from 20 and then multiplying the result by 10. For more than 20s, the score is 0.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">if</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition-1 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
 elseif condition-2 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
 elseif condition-3 then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-3 <br />
&nbsp;&nbsp;&nbsp;&nbsp;... <br />
 elseif condition-n then <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
&nbsp;&nbsp;&nbsp;&nbsp;[else <br />
&nbsp;&nbsp;&nbsp;&nbsp; code-block-n+1] <br />
}</code></div></div><br />
where<ul class="mycode_list"><li>condition-1, condition-2, ...: are Boolean expressions.<br />
</li>
<li>code-block-1, code-block-2, ...: each consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Switch Expression Syntax</span></span></span><br />
<br />
The <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expression has the following syntax:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{switch compare-expr [using compare-operator] <br />
 case value-1 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-1 <br />
 case value-2 do <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-2 <br />
&nbsp;&nbsp;&nbsp;&nbsp;... <br />
 case value-n do <br />
&nbsp;&nbsp;&nbsp;&nbsp;code-block-n <br />
&nbsp;&nbsp;[else code-block-n+1] <br />
}</code></div></div><br />
where<br />
<ul class="mycode_list"><li><span style="font-family: Courier;" class="mycode_font">compare-expr, value-1, value-2, value-n</span>: are Curl language expressions. These expressions can evaluate to any Curl language type.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">compare-operator</span>: is the operator that the Curl language uses when comparing compare-expr to <span style="font-family: Courier;" class="mycode_font">value-1, value-2</span>, and so on. When the comparison operator is omitted, “==” is used.<br />
</li>
<li><span style="font-family: Courier;" class="mycode_font">code-block-1, code-block-2, code-block-n</span>: consist of one or more Curl language expressions.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
Now, let’s consider the usage the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expression. This expression sets the initial value of the variable declared in the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">let</span></span> phrase. <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">if</span></span> and <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">switch</span></span> expressions that include an else clause can return a value.<br />
<br />
In our example, the values coded after do and else are used to initialize the variable score.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3-3. Displays a message.</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{popup-message {VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center font-size = 20pt, You have {value score} points! ! },<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center {value {start-time.elapsed}}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
}</code></div></div><br />
A message containing the score is displayed as a pop-up. <span style="color: #9400D3;" class="mycode_color">popup-message</span> is not limited to displaying character strings, but can also display graphical objects. Here, the <span style="color: #9400D3;" class="mycode_color">VBox</span> graphical container is displayed.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_18.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">4. Creating a screen layout with 'VBox'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;halign = center,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{bold Try to stop in 10 seconds},<br />
&nbsp;&nbsp;&nbsp;&nbsp;start-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;stop-btn<br />
}</code></div></div><br />
If we look at this expression in its entirety, we find that it is enclosed in large <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">value</span></span> expression. This creates a code block. Each <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">value</span></span> expression can itself contain multiple expressions. However, when there are multiple expressions, the result for the final expression is returned and displayed on the screen. For this example, the final expression begins with <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span>.<br />
<br />
<span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span> is a graphical container that is used to arrange objects vertically. The first three lines in this expression specify option values, which specify the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span> margins and the spacing between objects. The expression coded with bold appears in the <span style="color: #9400D3;" class="mycode_color"><span style="font-family: Courier;" class="mycode_font">VBox</span></span>, along with start-btn and stop-btn. These are arranged vertically.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Page 5: Application... A “Push the Button in 10s” Game]]></title>
			<link>https://communities.curl.com/showthread.php?tid=51</link>
			<pubDate>Thu, 16 Jun 2011 06:33:23 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=51</guid>
			<description><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Application... A “Push the Button in 10s” Game</span></span></span><br />
<br />
Let’s create a simple game that combines events and control. In this game, we have to press a “start” button and then, when we think that ten seconds have passed, press a “stop” button. The closer we are to exactly 10s, the higher is our score.<br />
<br />
<img src="wiki/easy-ide-book/common/images/step1.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Create the 'Try 2-3' Project</span></span></span><br />
<br />
Close the Try 2-2 project and then, from the IDE "File" menu, select "New Project". In the "New Project" dialog box, select "Applet Project”"(1), input “Try2-3” (2), specify <span style="font-family: Courier;" class="mycode_font">c:\Curl\lesson\Try2\03_game</span> in the "Directory" field (3), set the "API Version" to "6.0" (4), and then click "OK" (5).<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_15.png" /><br />
<br />
<img src="wiki/easy-ide-book/common/images/step2.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Inputting the Program</span></span></span><br />
<br />
Next, we’ll input the following program code. Or, if you prefer, you can copy the program from <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try2\03_game\start.curl</span> and then paste it into the editor.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-time:#DateTime<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-btn:CommandButton = {CommandButton label = Start}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let stop-btn:CommandButton = {CommandButton label = Stop}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{start-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = {DateTime}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{stop-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let elapsed-time:Time = {start-time.elapsed}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let time-double:double = elapsed-time / 1s<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let score:int = {switch time-double using &lt;=<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 10 do (time-double * 10) asa int<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 20 do {abs ((20 - time-double) * 10) asa int}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message {VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center font-size = 20pt, You have {value score} points!!},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {center {value {start-time.elapsed}}}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;halign = center,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{bold Try to stop in 10 seconds},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stop-btn<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<br />
<img src="wiki/easy-ide-book/common/images/step3.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Save the File and Execute the Program</span></span></span><br />
<br />
After inputting the code, save the file, and then execute the program. The following result will appear in your browser.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_16.png" /><br />
<br />
]]></description>
			<content:encoded><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Application... A “Push the Button in 10s” Game</span></span></span><br />
<br />
Let’s create a simple game that combines events and control. In this game, we have to press a “start” button and then, when we think that ten seconds have passed, press a “stop” button. The closer we are to exactly 10s, the higher is our score.<br />
<br />
<img src="wiki/easy-ide-book/common/images/step1.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Create the 'Try 2-3' Project</span></span></span><br />
<br />
Close the Try 2-2 project and then, from the IDE "File" menu, select "New Project". In the "New Project" dialog box, select "Applet Project”"(1), input “Try2-3” (2), specify <span style="font-family: Courier;" class="mycode_font">c:\Curl\lesson\Try2\03_game</span> in the "Directory" field (3), set the "API Version" to "6.0" (4), and then click "OK" (5).<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_15.png" /><br />
<br />
<img src="wiki/easy-ide-book/common/images/step2.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Inputting the Program</span></span></span><br />
<br />
Next, we’ll input the following program code. Or, if you prefer, you can copy the program from <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try2\03_game\start.curl</span> and then paste it into the editor.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{value<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-time:#DateTime<br />
&nbsp;&nbsp;&nbsp;&nbsp;let start-btn:CommandButton = {CommandButton label = Start}<br />
&nbsp;&nbsp;&nbsp;&nbsp;let stop-btn:CommandButton = {CommandButton label = Stop}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{start-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set start-time = {DateTime}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{stop-btn.add-event-handler<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let elapsed-time:Time = {start-time.elapsed}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let time-double:double = elapsed-time / 1s<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let score:int = {switch time-double using &lt;=<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 10 do (time-double * 10) asa int<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 20 do {abs ((20 - time-double) * 10) asa int}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{VBox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spacing = 10pt,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;halign = center,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{bold Try to stop in 10 seconds},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start-btn,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stop-btn<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<br />
<img src="wiki/easy-ide-book/common/images/step3.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Save the File and Execute the Program</span></span></span><br />
<br />
After inputting the code, save the file, and then execute the program. The following result will appear in your browser.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_16.png" /><br />
<br />
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Page 4: Structure of our program that uses events]]></title>
			<link>https://communities.curl.com/showthread.php?tid=50</link>
			<pubDate>Thu, 16 Jun 2011 06:30:19 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=50</guid>
			<description><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Structure of our program that uses events</span></span></span><br />
<br />
Let’s take a look at the program that we’ve created.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_12.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">1. Using the 'Frame' graphical container</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;height = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;width = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin = 1cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;background = orange,<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
A <span style="color: #9400D3;" class="mycode_color">Frame</span> is a kind of object called a graphical container. A graphical container is an object into which we can place other objects such as text, images, and controls. In addition to <span style="color: #9400D3;" class="mycode_color">Frame</span>s, there are many other types of graphical container, each with their own particular characteristics. By combining graphical containers, we can create compound screen layouts.<br />
<br />
<img src="attachment.php?aid=94" /><br />
Note: There are many other graphical containers in addition to those listed above <br />
<br />
By specifying options for a graphical object, we can adjust the visual properties of that object.<br />
<br />
<img src="attachment.php?aid=95" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">2. 'PointerPress' and 'PointerRelease' event processing</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #00FF00<br />
&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
},<br />
{on e:PointerRelease at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;set f.background = pink<br />
&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
}</code></div></div><br />
This is the event handler that appeared previously. When the mouse button is pressed, a <span style="color: #9400D3;" class="mycode_color">PointerPress</span> event is generated, while when the button is released, a <span style="color: #9400D3;" class="mycode_color">PointerRelease</span> event is generated. A name can be given to the event object (e<img src="https://communities.curl.com/images/smilies/tongue.gif" alt="Tongue" title="Tongue" class="smilie smilie_5" />ointerRelease) and referenced in the event handler expression. This is similar to giving a name to the target object (f:Frame) where the event is fired.<br />
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event Handler Definition 3</span></span></span><br />
<br />
The following further expands the on syntax: {on event-var:event-type at target-var[:target-type] do body} where <br />
<ul class="mycode_list"><li>event-var:event-type binds a variable to the event object.<br />
</li>
<li>Use event-var if you need to access methods or properties of the event..<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<img src="attachment.php?aid=96" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. Consuming an Event</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #00FF00<br />
&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
}</code></div></div><br />
Next, let’s look at the role of the consume that is inserted after the event handler code. A GUI event traverses a graphical hierarchy. To explain this, let’s consider a graphical container with a hierarchical structure. First, assume a hierarchical structure with three graphical objects: A, B, and C.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_13.png" /><br />
<br />
For each of objects A, B, and C, we’ll also assume the definition of an event handler that changes their colors when they are clicked. So, assume that the user clicks object C. A <span style="color: #9400D3;" class="mycode_color">PointerPress</span> event is generated and this is communicated to C. C then calls the event handler, which then changes C’s color. The generated event is then communicated to B. As a result, the color of B is changed in the same way. And, again, this event is communicated to A, such that the color of A is changed.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_14.png" /><br />
<br />
In this way, generated events are communicated to external objects in a given order. If, however, we don’t want an event to be communicated to an external object, then we have to 'consume' that object. So we insert a consume.<br />
<br />
By using consume, we consume an event to prevent it from being communicated to an external object. Try commenting-out each instance of e.consume in the previous source code, and then execute the code to see how the results differ.<br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=94" target="_blank" title="">2-1.PNG</a> (Size: 14.72 KB / Downloads: 1336)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=95" target="_blank" title="">2-2.PNG</a> (Size: 8.27 KB / Downloads: 1391)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=96" target="_blank" title="">2-3.PNG</a> (Size: 11.68 KB / Downloads: 1267)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Structure of our program that uses events</span></span></span><br />
<br />
Let’s take a look at the program that we’ve created.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_12.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">1. Using the 'Frame' graphical container</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;height = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;width = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin = 1cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;background = orange,<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
A <span style="color: #9400D3;" class="mycode_color">Frame</span> is a kind of object called a graphical container. A graphical container is an object into which we can place other objects such as text, images, and controls. In addition to <span style="color: #9400D3;" class="mycode_color">Frame</span>s, there are many other types of graphical container, each with their own particular characteristics. By combining graphical containers, we can create compound screen layouts.<br />
<br />
<img src="attachment.php?aid=94" /><br />
Note: There are many other graphical containers in addition to those listed above <br />
<br />
By specifying options for a graphical object, we can adjust the visual properties of that object.<br />
<br />
<img src="attachment.php?aid=95" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">2. 'PointerPress' and 'PointerRelease' event processing</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #00FF00<br />
&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
},<br />
{on e:PointerRelease at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;set f.background = pink<br />
&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
}</code></div></div><br />
This is the event handler that appeared previously. When the mouse button is pressed, a <span style="color: #9400D3;" class="mycode_color">PointerPress</span> event is generated, while when the button is released, a <span style="color: #9400D3;" class="mycode_color">PointerRelease</span> event is generated. A name can be given to the event object (e<img src="https://communities.curl.com/images/smilies/tongue.gif" alt="Tongue" title="Tongue" class="smilie smilie_5" />ointerRelease) and referenced in the event handler expression. This is similar to giving a name to the target object (f:Frame) where the event is fired.<br />
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event Handler Definition 3</span></span></span><br />
<br />
The following further expands the on syntax: {on event-var:event-type at target-var[:target-type] do body} where <br />
<ul class="mycode_list"><li>event-var:event-type binds a variable to the event object.<br />
</li>
<li>Use event-var if you need to access methods or properties of the event..<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<img src="attachment.php?aid=96" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. Consuming an Event</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #00FF00<br />
&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
}</code></div></div><br />
Next, let’s look at the role of the consume that is inserted after the event handler code. A GUI event traverses a graphical hierarchy. To explain this, let’s consider a graphical container with a hierarchical structure. First, assume a hierarchical structure with three graphical objects: A, B, and C.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_13.png" /><br />
<br />
For each of objects A, B, and C, we’ll also assume the definition of an event handler that changes their colors when they are clicked. So, assume that the user clicks object C. A <span style="color: #9400D3;" class="mycode_color">PointerPress</span> event is generated and this is communicated to C. C then calls the event handler, which then changes C’s color. The generated event is then communicated to B. As a result, the color of B is changed in the same way. And, again, this event is communicated to A, such that the color of A is changed.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_14.png" /><br />
<br />
In this way, generated events are communicated to external objects in a given order. If, however, we don’t want an event to be communicated to an external object, then we have to 'consume' that object. So we insert a consume.<br />
<br />
By using consume, we consume an event to prevent it from being communicated to an external object. Try commenting-out each instance of e.consume in the previous source code, and then execute the code to see how the results differ.<br />
<br />
<br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=94" target="_blank" title="">2-1.PNG</a> (Size: 14.72 KB / Downloads: 1336)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=95" target="_blank" title="">2-2.PNG</a> (Size: 8.27 KB / Downloads: 1391)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://communities.curl.com/images/attachtypes/image.gif" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=96" target="_blank" title="">2-3.PNG</a> (Size: 11.68 KB / Downloads: 1267)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Page 3: Using Different Events]]></title>
			<link>https://communities.curl.com/showthread.php?tid=49</link>
			<pubDate>Thu, 16 Jun 2011 06:25:33 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=49</guid>
			<description><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Using Different Events</span></span></span><br />
<br />
<br />
In the previous section, we processed events related to command buttons and check buttons. Next, let’s consider events that are not related to controls.<br />
<br />
<br />
<img src="wiki/easy-ide-book/common/images/step1.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Create the 'Try 2-2' Project</span></span></span><br />
<br />
Close the Try 2-1 project and then, from the IDE “File” menu, select “New Project.” In the "New Project" dialog box, select "Applet Project" (1), input "Try2-2" (2), specify <span style="font-family: Courier;" class="mycode_font">c:\Curl\lesson\Try2\02_event</span> in the “Directory” field (3), set the "API Version" to "6.0" (4), and then click "OK" (5).<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_10.png" /><br />
<br />
<br />
<img src="wiki/easy-ide-book/common/images/step2.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Inputting the Program</span></span></span><br />
<br />
Next, we’ll input the following program code. Or, if you prefer, you can copy the program from <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try2\02_event\start.curl</span> and then paste it into the editor.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;height = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;width = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin = 1cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;background = orange,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height = 3cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width = 3cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background = pink,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #00FF00<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerRelease at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = pink<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #FF0000<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerRelease at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = orange<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<img src="wiki/easy-ide-book/common/images/step3.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Save the File, and then Execute the Program</span></span></span><br />
<br />
After inputting the code, save the file, and then execute the program. As a result, your browser will display an orange-colored <span style="color: #9400D3;" class="mycode_color">Frame</span>, inside of which is a pink <span style="color: #9400D3;" class="mycode_color">Frame</span>. If we click the inside <span style="color: #9400D3;" class="mycode_color">Frame</span>, its color changes from pink to lime-green. And, if we click the outside <span style="color: #9400D3;" class="mycode_color">Frame</span>, it changes from orange to red.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_11.png" /><br />
<br />
<br />
]]></description>
			<content:encoded><![CDATA[<span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Using Different Events</span></span></span><br />
<br />
<br />
In the previous section, we processed events related to command buttons and check buttons. Next, let’s consider events that are not related to controls.<br />
<br />
<br />
<img src="wiki/easy-ide-book/common/images/step1.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Create the 'Try 2-2' Project</span></span></span><br />
<br />
Close the Try 2-1 project and then, from the IDE “File” menu, select “New Project.” In the "New Project" dialog box, select "Applet Project" (1), input "Try2-2" (2), specify <span style="font-family: Courier;" class="mycode_font">c:\Curl\lesson\Try2\02_event</span> in the “Directory” field (3), set the "API Version" to "6.0" (4), and then click "OK" (5).<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_10.png" /><br />
<br />
<br />
<img src="wiki/easy-ide-book/common/images/step2.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Inputting the Program</span></span></span><br />
<br />
Next, we’ll input the following program code. Or, if you prefer, you can copy the program from <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try2\02_event\start.curl</span> and then paste it into the editor.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;height = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;width = 5cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin = 1cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;background = orange,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{Frame<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height = 3cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width = 3cm,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background = pink,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #00FF00<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerRelease at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = pink<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerPress at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = #FF0000<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;},<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on e:PointerRelease at f:Frame do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set f.background = orange<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{e.consume}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<img src="wiki/easy-ide-book/common/images/step3.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Save the File, and then Execute the Program</span></span></span><br />
<br />
After inputting the code, save the file, and then execute the program. As a result, your browser will display an orange-colored <span style="color: #9400D3;" class="mycode_color">Frame</span>, inside of which is a pink <span style="color: #9400D3;" class="mycode_color">Frame</span>. If we click the inside <span style="color: #9400D3;" class="mycode_color">Frame</span>, its color changes from pink to lime-green. And, if we click the outside <span style="color: #9400D3;" class="mycode_color">Frame</span>, it changes from orange to red.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_11.png" /><br />
<br />
<br />
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Page 2: Structure of a Program that Displays Values input from Controls]]></title>
			<link>https://communities.curl.com/showthread.php?tid=48</link>
			<pubDate>Thu, 16 Jun 2011 05:18:57 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=48</guid>
			<description><![CDATA[<img src="wiki/easy-ide-book/common/images/topic.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Structure of a program that displays values input from controls</span></span></span><br />
<br />
The program covered in this chapter introduces many new elements. We’ll look at these in order.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_4.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">1. Displaying a command button “CommandButton”</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Push the button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
To display a command button in Curl, we use <span style="color: #9400D3;" class="mycode_color">CommandButton</span>. Using an option called label, we can specify the label that is displayed on the <span style="color: #9400D3;" class="mycode_color">CommandButton</span>. In this example, we specified a character string, but just like in Try 1, we could also specify an image file as the label.<br />
<br />
In addition to the label option, there is also control-color (used to specify a button color) and style (for specifying the style of the button). Next, change the code as shown below and then check the results.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Push the button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;control-color = green,<br />
&nbsp;&nbsp;&nbsp;&nbsp;style = rollover<br />
}</code></div></div> <br />
<br />
Search for <span style="color: #9400D3;" class="mycode_color">CommandButton</span> in the Help, and note the different options that are supported.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/hint.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Types of Controls</span></span></span><br />
<ul class="mycode_list"><li>Button controls: <span style="color: #9400D3;" class="mycode_color">CommandButton</span>, <span style="color: #9400D3;" class="mycode_color">CheckButton</span>, <span style="color: #9400D3;" class="mycode_color">RadioButton</span><br />
</li>
<li>Text controls <span style="color: #9400D3;" class="mycode_color">TextDisplay</span>, <span style="color: #9400D3;" class="mycode_color">TextField</span>, <span style="color: #9400D3;" class="mycode_color">PasswordField</span>, <span style="color: #9400D3;" class="mycode_color">TextArea</span>, <span style="color: #9400D3;" class="mycode_color">RichTextArea</span><br />
</li>
<li>List controls <span style="color: #9400D3;" class="mycode_color">ListBox</span>, <span style="color: #9400D3;" class="mycode_color">DropdownList</span>, <span style="color: #9400D3;" class="mycode_color">ComboBox</span>, <span style="color: #9400D3;" class="mycode_color">ColorDropdown</span><br />
</li>
<li>Other controls <span style="color: #9400D3;" class="mycode_color">SpinControl</span>, <span style="color: #9400D3;" class="mycode_color">CalendarControl</span>, <span style="color: #9400D3;" class="mycode_color">DateField</span>, <span style="color: #9400D3;" class="mycode_color">ProgressBar</span>, <span style="color: #9400D3;" class="mycode_color">Slider</span>, <span style="color: #9400D3;" class="mycode_color">GroupBox</span><br />
</li>
</ul>
In addition to the above, there is also the <span style="color: #9400D3;" class="mycode_color">RecordGrid</span> data control, <span style="color: #9400D3;" class="mycode_color">TabContainer</span>, and <span style="color: #9400D3;" class="mycode_color">TreeControl</span>.<br />
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">2. Event handler 'on Action do'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on Action do<br />
&nbsp;&nbsp; ...<br />
}</code></div></div><br />
When a command button is pressed, an event named “Action” is generated. Upon the generation of this event, the {on Action do } code (event handler) is executed.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event Handler Definition 1</span></span></span><br />
<br />
The following shows the on syntax in the simplest form: {on event-class do body} where <br />
<ul class="mycode_list"><li>event-class specifies the class of the event it handles.<br />
</li>
<li>body is the code for the event handler procedure.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. Display of a pop-up message 'popup-message'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{popup-message “Thank you!”}</code></div></div><br />
The popup-message expression is designed to display a popup dialog box.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_5.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">4. Creating a check button 'CheckButton'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{CheckButton <br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Select the check button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
This style is used to create a check button. In the same way as for &lt;font color="purple"&gt;CommandButton&lt;/font&gt;, a variety of options are supported. Take a look at these in the Help.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">5. Event handler 'on ValueChanged at'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on ValueChanged at c:CheckButton do ...}</code></div></div><br />
Placing a check mark in a box, subsequently removing it, and changing a value all cause a <span style="color: #9400D3;" class="mycode_color">ValueChanged</span> event to be generated. This time, we have an at component to the event handler expression that we did not see in the explanation of the <span style="color: #9400D3;" class="mycode_color">CommandButton</span> event handler. By adding an at after the name of an event, and appending a variable name for the target of the event (in this case <span style="color: #9400D3;" class="mycode_color">CheckButton</span>), we can reference it within the event handler expression. In this example, c is used as the name of the <span style="color: #9400D3;" class="mycode_color">CheckButton</span> that causes the event to occur.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event Handler Definition 2</span></span></span><br />
<br />
Here is a more general form of the on syntax: {<span style="font-family: Courier;" class="mycode_font">on event-type at target-var[:target-type]do body}</span> where <ul class="mycode_list"><li>target-var\[:target-type\] binds a variable to the target.<br />
</li>
<li>If target-type is not specified, it defaults to any.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">6. Conditional branches beginning with 'if'</span></span></span><br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if c.value then<br />
&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now on.}<br />
 else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now off.}<br />
}</code></div></div>The above is an example of a conditional branch. The processing to be performed is determined by the condition. For example, if we look at “Is today a holiday?” then the processing to be performed is “Go out and enjoy myself” for YES, or “Go to work” for NO. We can illustrate this processing as follows.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_6.png" /><br />
<img src="wiki/easy-ide-book/try2/images/figure_2_7.png" /><br />
<br />
Putting this into more general terms, we get this:<br />
<br />
<br />
Describing this in Curl produces the following:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition then<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 1<br />
 else<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 2<br />
}</code></div></div><br />
When the condition is false, and we want to test other conditions then we can use elseif to add more branches. This would be described as follows:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition1 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 1<br />
 elseif condition2 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 2<br />
&nbsp;&nbsp;&nbsp;&nbsp;…<br />
 elseif condition n then <br />
&nbsp;&nbsp;&nbsp;&nbsp;processing n<br />
 else<br />
&nbsp;&nbsp;&nbsp;&nbsp;processing n+1<br />
}</code></div></div><br />
Figure 2-8 illustrates this structure.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_8.png" /><br />
<br />
<br />
So, let’s apply this conditional branching to our example. As the condition, we code c.value where c represents the check button and c.value lets us acquire the value of the check button. When a check mark is placed in the check button, the value is true, while when there is no check mark, the value is false.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_9.png" /><br />
<br />
So, when the value of a command button changes, or if a check mark is placed in a check button, a message stating “Check is now on” is displayed. Otherwise, “Check is now off” is displayed.]]></description>
			<content:encoded><![CDATA[<img src="wiki/easy-ide-book/common/images/topic.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Structure of a program that displays values input from controls</span></span></span><br />
<br />
The program covered in this chapter introduces many new elements. We’ll look at these in order.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_4.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">1. Displaying a command button “CommandButton”</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Push the button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
To display a command button in Curl, we use <span style="color: #9400D3;" class="mycode_color">CommandButton</span>. Using an option called label, we can specify the label that is displayed on the <span style="color: #9400D3;" class="mycode_color">CommandButton</span>. In this example, we specified a character string, but just like in Try 1, we could also specify an image file as the label.<br />
<br />
In addition to the label option, there is also control-color (used to specify a button color) and style (for specifying the style of the button). Next, change the code as shown below and then check the results.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Push the button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;control-color = green,<br />
&nbsp;&nbsp;&nbsp;&nbsp;style = rollover<br />
}</code></div></div> <br />
<br />
Search for <span style="color: #9400D3;" class="mycode_color">CommandButton</span> in the Help, and note the different options that are supported.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/hint.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Types of Controls</span></span></span><br />
<ul class="mycode_list"><li>Button controls: <span style="color: #9400D3;" class="mycode_color">CommandButton</span>, <span style="color: #9400D3;" class="mycode_color">CheckButton</span>, <span style="color: #9400D3;" class="mycode_color">RadioButton</span><br />
</li>
<li>Text controls <span style="color: #9400D3;" class="mycode_color">TextDisplay</span>, <span style="color: #9400D3;" class="mycode_color">TextField</span>, <span style="color: #9400D3;" class="mycode_color">PasswordField</span>, <span style="color: #9400D3;" class="mycode_color">TextArea</span>, <span style="color: #9400D3;" class="mycode_color">RichTextArea</span><br />
</li>
<li>List controls <span style="color: #9400D3;" class="mycode_color">ListBox</span>, <span style="color: #9400D3;" class="mycode_color">DropdownList</span>, <span style="color: #9400D3;" class="mycode_color">ComboBox</span>, <span style="color: #9400D3;" class="mycode_color">ColorDropdown</span><br />
</li>
<li>Other controls <span style="color: #9400D3;" class="mycode_color">SpinControl</span>, <span style="color: #9400D3;" class="mycode_color">CalendarControl</span>, <span style="color: #9400D3;" class="mycode_color">DateField</span>, <span style="color: #9400D3;" class="mycode_color">ProgressBar</span>, <span style="color: #9400D3;" class="mycode_color">Slider</span>, <span style="color: #9400D3;" class="mycode_color">GroupBox</span><br />
</li>
</ul>
In addition to the above, there is also the <span style="color: #9400D3;" class="mycode_color">RecordGrid</span> data control, <span style="color: #9400D3;" class="mycode_color">TabContainer</span>, and <span style="color: #9400D3;" class="mycode_color">TreeControl</span>.<br />
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">2. Event handler 'on Action do'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on Action do<br />
&nbsp;&nbsp; ...<br />
}</code></div></div><br />
When a command button is pressed, an event named “Action” is generated. Upon the generation of this event, the {on Action do } code (event handler) is executed.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event Handler Definition 1</span></span></span><br />
<br />
The following shows the on syntax in the simplest form: {on event-class do body} where <br />
<ul class="mycode_list"><li>event-class specifies the class of the event it handles.<br />
</li>
<li>body is the code for the event handler procedure.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">3. Display of a pop-up message 'popup-message'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{popup-message “Thank you!”}</code></div></div><br />
The popup-message expression is designed to display a popup dialog box.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_5.png" /><br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">4. Creating a check button 'CheckButton'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{CheckButton <br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Select the check button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
}</code></div></div><br />
This style is used to create a check button. In the same way as for &lt;font color="purple"&gt;CommandButton&lt;/font&gt;, a variety of options are supported. Take a look at these in the Help.<br />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">5. Event handler 'on ValueChanged at'</span></span></span><br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{on ValueChanged at c:CheckButton do ...}</code></div></div><br />
Placing a check mark in a box, subsequently removing it, and changing a value all cause a <span style="color: #9400D3;" class="mycode_color">ValueChanged</span> event to be generated. This time, we have an at component to the event handler expression that we did not see in the explanation of the <span style="color: #9400D3;" class="mycode_color">CommandButton</span> event handler. By adding an at after the name of an event, and appending a variable name for the target of the event (in this case <span style="color: #9400D3;" class="mycode_color">CheckButton</span>), we can reference it within the event handler expression. In this example, c is used as the name of the <span style="color: #9400D3;" class="mycode_color">CheckButton</span> that causes the event to occur.<br />
<br />
<hr class="mycode_hr" />
<br />
<img src="wiki/easy-ide-book/common/images/syntax.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Event Handler Definition 2</span></span></span><br />
<br />
Here is a more general form of the on syntax: {<span style="font-family: Courier;" class="mycode_font">on event-type at target-var[:target-type]do body}</span> where <ul class="mycode_list"><li>target-var\[:target-type\] binds a variable to the target.<br />
</li>
<li>If target-type is not specified, it defaults to any.<br />
</li>
</ul>
<br />
<hr class="mycode_hr" />
<br />
<span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">6. Conditional branches beginning with 'if'</span></span></span><br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if c.value then<br />
&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now on.}<br />
 else<br />
&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now off.}<br />
}</code></div></div>The above is an example of a conditional branch. The processing to be performed is determined by the condition. For example, if we look at “Is today a holiday?” then the processing to be performed is “Go out and enjoy myself” for YES, or “Go to work” for NO. We can illustrate this processing as follows.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_6.png" /><br />
<img src="wiki/easy-ide-book/try2/images/figure_2_7.png" /><br />
<br />
Putting this into more general terms, we get this:<br />
<br />
<br />
Describing this in Curl produces the following:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition then<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 1<br />
 else<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 2<br />
}</code></div></div><br />
When the condition is false, and we want to test other conditions then we can use elseif to add more branches. This would be described as follows:<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{if condition1 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 1<br />
 elseif condition2 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;Processing 2<br />
&nbsp;&nbsp;&nbsp;&nbsp;…<br />
 elseif condition n then <br />
&nbsp;&nbsp;&nbsp;&nbsp;processing n<br />
 else<br />
&nbsp;&nbsp;&nbsp;&nbsp;processing n+1<br />
}</code></div></div><br />
Figure 2-8 illustrates this structure.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_8.png" /><br />
<br />
<br />
So, let’s apply this conditional branching to our example. As the condition, we code c.value where c represents the check button and c.value lets us acquire the value of the check button. When a check mark is placed in the check button, the value is true, while when there is no check mark, the value is false.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_9.png" /><br />
<br />
So, when the value of a command button changes, or if a check mark is placed in a check button, a message stating “Check is now on” is displayed. Otherwise, “Check is now off” is displayed.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Page 1: Making a Simple Action Game]]></title>
			<link>https://communities.curl.com/showthread.php?tid=47</link>
			<pubDate>Thu, 16 Jun 2011 05:03:09 +0000</pubDate>
			<guid isPermaLink="false">https://communities.curl.com/showthread.php?tid=47</guid>
			<description><![CDATA[<img src="wiki/easy-ide-book/common/images/try.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Try 2: Making a Simple Action Game</span></span></span><br />
<br />
We can gather data from a user by using controls, which include buttons, lists, and input fields. And, by using events, we can perform processing according to the user’s actions. In this chapter, we’re going to create a simple game using controls and events.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Please download the <span style="font-family: Courier;" class="mycode_font">Try2.zip</span> file by selecting the following link: <span style="font-family: Courier;" class="mycode_font"><a href="http://developers.curl.com/wiki/easy-ide-book/try2/Try2.zip" target="_blank" rel="noopener" class="mycode_url">Try2.zip</a></span>. </span><br />
<br />
Unzip the contents to the <span style="font-family: Courier;" class="mycode_font">C:\Curl</span> directory. This is the working directory for all the examples and exercises contained within this tutorial. Note: If C:\Curl has not already been created, you can create it now.<br />
<br />
<img src="wiki/easy-ide-book/common/images/topic.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">The Basics: Displaying Values that are Input from a Control</span></span></span><br />
<br />
<img src="wiki/easy-ide-book/common/images/step1.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Create the 'Try 2-1' Project</span></span></span><br />
<br />
1. Close the Try 1 project. From the “File” menu, select “Close Project.”<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_1.png" /><br />
<br />
<img src="wiki/easy-ide-book/common/images/hint.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Opening multiple projects in the IDE</span></span></span><br />
<br />
<hr class="mycode_hr" />
<br />
For clarity, in this manual we only ever open and then edit a single project. The Curl IDE, however, supports the simultaneous opening of multiple projects. <br />
<br />
<hr class="mycode_hr" />
<br />
2. Next, from the IDE “File” menu, select “New Project.” In the “New Project” dialog box, select “Applet Project” (1), input “Try2-1” (2), specify c:\Curl\lesson\Try2\01_control_action in the “Directory” field (3), set the API Version to 6.0 (4), and then click OK (5).<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_2.png" /><br />
<br />
<img src="wiki/easy-ide-book/common/images/step2.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Inputting the Program</span></span></span> <br />
<br />
Next, we’ll input the program. You can copy the program code below or use <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try2\01_control_action\start.curl</span> and then paste it into the editor in the IDE.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Push the button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Thank you!<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
{CheckButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Select the checkbox,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on ValueChanged at c:CheckButton do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{if c.value then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now on.}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now off.}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<img src="wiki/easy-ide-book/common/images/step3.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Save the File, and then Execute the Program</span></span></span><br />
<br />
After inputting the code, save the file, and then execute the program. The following result will appear in your browser. Push the button and select the checkbox, while noting the results.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_3.png" /><br />
<br />
]]></description>
			<content:encoded><![CDATA[<img src="wiki/easy-ide-book/common/images/try.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Try 2: Making a Simple Action Game</span></span></span><br />
<br />
We can gather data from a user by using controls, which include buttons, lists, and input fields. And, by using events, we can perform processing according to the user’s actions. In this chapter, we’re going to create a simple game using controls and events.<br />
<br />
<span style="font-weight: bold;" class="mycode_b">Please download the <span style="font-family: Courier;" class="mycode_font">Try2.zip</span> file by selecting the following link: <span style="font-family: Courier;" class="mycode_font"><a href="http://developers.curl.com/wiki/easy-ide-book/try2/Try2.zip" target="_blank" rel="noopener" class="mycode_url">Try2.zip</a></span>. </span><br />
<br />
Unzip the contents to the <span style="font-family: Courier;" class="mycode_font">C:\Curl</span> directory. This is the working directory for all the examples and exercises contained within this tutorial. Note: If C:\Curl has not already been created, you can create it now.<br />
<br />
<img src="wiki/easy-ide-book/common/images/topic.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">The Basics: Displaying Values that are Input from a Control</span></span></span><br />
<br />
<img src="wiki/easy-ide-book/common/images/step1.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Create the 'Try 2-1' Project</span></span></span><br />
<br />
1. Close the Try 1 project. From the “File” menu, select “Close Project.”<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_1.png" /><br />
<br />
<img src="wiki/easy-ide-book/common/images/hint.gif" /><span style="font-size: large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Opening multiple projects in the IDE</span></span></span><br />
<br />
<hr class="mycode_hr" />
<br />
For clarity, in this manual we only ever open and then edit a single project. The Curl IDE, however, supports the simultaneous opening of multiple projects. <br />
<br />
<hr class="mycode_hr" />
<br />
2. Next, from the IDE “File” menu, select “New Project.” In the “New Project” dialog box, select “Applet Project” (1), input “Try2-1” (2), specify c:\Curl\lesson\Try2\01_control_action in the “Directory” field (3), set the API Version to 6.0 (4), and then click OK (5).<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_2.png" /><br />
<br />
<img src="wiki/easy-ide-book/common/images/step2.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Inputting the Program</span></span></span> <br />
<br />
Next, we’ll input the program. You can copy the program code below or use <span style="font-family: Courier;" class="mycode_font">c:\Curl\Try2\01_control_action\start.curl</span> and then paste it into the editor in the IDE.<br />
<br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{CommandButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Push the button,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on Action do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Thank you!<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
{CheckButton<br />
&nbsp;&nbsp;&nbsp;&nbsp;label = Select the checkbox,<br />
&nbsp;&nbsp;&nbsp;&nbsp;{on ValueChanged at c:CheckButton do<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{if c.value then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now on.}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{popup-message Check is now off.}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</code></div></div><br />
<img src="wiki/easy-ide-book/common/images/step3.gif" /><span style="font-size: x-large;" class="mycode_size"><span style="font-family: Arial;" class="mycode_font"><span style="font-weight: bold;" class="mycode_b">Save the File, and then Execute the Program</span></span></span><br />
<br />
After inputting the code, save the file, and then execute the program. The following result will appear in your browser. Push the button and select the checkbox, while noting the results.<br />
<img src="wiki/easy-ide-book/try2/images/figure_2_3.png" /><br />
<br />
]]></content:encoded>
		</item>
	</channel>
</rss>