<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>No Open Blockers &#187; Code Samples</title>
	<atom:link href="http://noopenblockers.com/category/code-samples/feed/" rel="self" type="application/rss+xml" />
	<link>http://noopenblockers.com</link>
	<description></description>
	<lastBuildDate>Thu, 01 Jul 2010 14:43:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Back to the drawing board</title>
		<link>http://noopenblockers.com/2009/03/09/back-to-the-drawing-board/</link>
		<comments>http://noopenblockers.com/2009/03/09/back-to-the-drawing-board/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 01:49:54 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Code Samples]]></category>

		<guid isPermaLink="false">http://notebook.novasurv.com/?p=349</guid>
		<description><![CDATA[Programming is very much an iterative process, especially when you&#8217;re not entirely clear what you&#8217;re trying to do when you first start. It&#8217;s a good practice to look back and question certain aspects of a design. I&#8217;m at that point with CodeTurtle, and I&#8217;m not entirely surprised to be here. I knew that once I [...]]]></description>
			<content:encoded><![CDATA[<p>Programming is very much an iterative process, especially when you&#8217;re not entirely clear what you&#8217;re trying to do when you first start. It&#8217;s a good practice to look back and question certain aspects of a design. I&#8217;m at that point with CodeTurtle, and I&#8217;m not entirely surprised to be here. I knew that once I started to use it I was going to get a feeling for the two main aspects: the UI and the API for grading projects. I&#8217;m (somewhat surprisingly) pretty happy with the UI as it stands today, but the project grading needs some love. With spring break this week, I&#8217;m in a prime position to make some solid infrastructure changes in time to get the third project graded before we return from break. </p>
<p>Originally, I started out with a pretty simplistic idea. I planned on running various tests against the submission and indicate if points should be awarded for each verification (a grade item). It was loosely based on the idea of being a unit test framework with points. There was a very vague concept of relating tests to each other by way of a string in each grade item called the test suite.</p>
<p>This has a few primary issues:</p>
<ul>
<li>There is no real sense of aggregation of the grade items. I had a way to assign a &#8220;test suite&#8221; name to them, but that wasn&#8217;t sufficient.</li>
<li>There is no way of saying &#8220;this is the total amount of points for the project&#8221;. I didn&#8217;t want to put grader developers in a position of declaring that there was 150 possible points and then making sure the grade items summed to that total. Instead, I calculate the total as the grade items are added to the project&#8217;s grade. I stand by this approach, but it has a bitch of a flaw: if there is an unexpected error from the student&#8217;s submission (as students, it&#8217;s understandable that this is a pretty common occurrence) and the grade items are not added, that project has a lower total grade than the rest.</li>
<li>The grader developer has to implement one method (grade()) as the hook into CodeTurtle. That means any protection against the above scenario must be provided in the grader itself. This led to a lot of try/catch blocks as the grader&#8217;s grade() method called out to smaller grade methods.</li>
</ul>
<p>After some time at my whiteboard, I came up with the following changes.</p>
<ul>
<li>The model now goes: a project grader has one or more grade test methods, each of which has one or more grade assertions. The idea of an aggregation of grade assertions is now a first-class concept.</li>
<li>Each grade test method is run by CodeTurtle independently of each other, preventing an unexpected error in one from stopping the execution of the others.</li>
<li>The domain model has been changed to reflect this, allowing an unexpected error in a grade test to be captured and indicated at the test level (as compared to simply a failed assertion).</li>
<li>Grade tests are indicated through the @GradeTest annotation. It takes a name parameter that is the display name used on the report.</li>
<li>Additionally, @Setup and @Teardown annotations indicate methods that should be run at the start and end of running all of the tests (yes, this looks very much like JUnit, it&#8217;s intentional).</li>
<li>All project graders must extend the ProjectGrader base class, which provides (among other things) the all important register() method (more on that later).</li>
</ul>
<p>The most important change is how grade assertions are created. At the start of each grade test, the register() method should be run for each assertion that will take place over the course of that test. The register method returns a GradeAssertion object that can be used later in the method to indicate the success/failure of each assertion (through the new correct() and incorrect(String result) methods respectively).</p>
<p>This was a big change as it allows me to dynamically calculate the total number of points instead of requiring the grader developer to manually add up the total points, but with a much greater degree of safety than previously offered. Making these calls to register at the outset of a test method guarantees that any unexpected exception that occurs will still result in a correct total. Capturing the unexpected exception and associating it with the test itself provides an explanation of why some assertions may not have been run.</p>
<p>To add some concreteness to this, here&#8217;s a quick example of what a grader might look like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CalcGrader <span style="color: #000000; font-weight: bold;">extends</span> ProjectGrader <span style="color: #009900;">&#123;</span>
&nbsp;
  @GraderTest<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Add Test&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    GradeAssertion twoNums <span style="color: #339933;">=</span> register<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>,
      <span style="color: #0000ff;">&quot;Adds two numbers correctly&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    GradeAssertion nullNums <span style="color: #339933;">=</span> register<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>,
      <span style="color: #0000ff;">&quot;Handles null parameter&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Setup to get to student's add method</span>
    <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> add<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      twoNums.<span style="color: #006633;">correct</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      twoNums.<span style="color: #006633;">incorrect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Adding [2, 3] failed. Expected [5],&quot;</span> <span style="color: #339933;">+</span> 
      <span style="color: #0000ff;">&quot;Found [&quot;</span> <span style="color: #339933;">+</span> result <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      add<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      nullNums.<span style="color: #006633;">incorrect</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">&quot;Null parameters did not cause exception&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IllegalArgumentException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      nullNums.<span style="color: #006633;">correct</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>It&#8217;s a bitch changing a domain model (in this case, adding a layer for GradeTest in between Grade and GradeAssertion). I think I got everything hashed out, short of a few variables that may still carry the old naming (GradeItem became GradeAssertion). So far, so good, as grading project 3 was significantly easier and cleaner than it was when I started it on the old model. There are still a few more projects in the semester, so I&#8217;ll have a few more chances to see how this stands up before actually declaring CodeTurtle &#8220;1.0&#8243;.</p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2009/03/09/back-to-the-drawing-board/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java enum</title>
		<link>http://noopenblockers.com/2009/02/09/java-enum/</link>
		<comments>http://noopenblockers.com/2009/02/09/java-enum/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 01:57:23 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://notebook.novasurv.com/?p=296</guid>
		<description><![CDATA[One of the cooler features introduced in JDK 1.5 was the enum keyword.
In short, an enum is a collection of constant values. They provide a simple way of limiting the options you can use for a variable if there are only a standard, or in other words enumerated, set of values it can be.
For instance, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the cooler features introduced in JDK 1.5 was the enum keyword.</p>
<p>In short, an enum is a collection of constant values. They provide a simple way of limiting the options you can use for a variable if there are only a standard, or in other words enumerated, set of values it can be.</p>
<p>For instance, imagine if you were modeling a deck of cards. Each card would be one of 4 possible suits: clubs, diamonds, spades, or hearts. One option is to store the suit in a string variable, however this is cumbersome for two reasons:</p>
<ul>
<li>There has to be careful validation in the setter for the suit to ensure only the four possible suits are allowed, taking into account the capitalization of the string.</li>
<li>If you needed to do different handling based on the suit, if/elses would have to be used; a switch statement cannot be used on strings.</li>
</ul>
<p>Instead of using a string to track the suit, an enum is a good candidate. An enum is defined just like a class except using the enum keyword instead of class. Also like a class, an enum is typically defined in its own file of the same name.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">enum</span> Suit <span style="color: #009900;">&#123;</span>
    HEARTS, CLUBS, SPADES, DIAMONDS
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A simple enum, which is usually sufficient, just lists the possible values. Since these values are effectively constant, the convention is the same as for final variables (all caps).</p>
<p>Using an enum is the same as any other object:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Card <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Suit suit<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Suit getSuit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> suit<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSuit<span style="color: #009900;">&#40;</span>Suit s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        suit <span style="color: #339933;">=</span> s<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When attempting to set a suit on a card, the compiler will only allow one of the four values defined in the enum, so there is no need to add validation in the setter. The value is accessed by using the enum name and the value name, similar to calling a static method or variable:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">Card card <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Card<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
card.<span style="color: #006633;">setSuit</span><span style="color: #009900;">&#40;</span>Suit.<span style="color: #006633;">DIAMONDS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If for some reason, we needed to do different handling based on suit (not an overly applicable scenario in this use case, but often a common usage of enums), enums are supported in switch statements:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>myVariable<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">case</span> Suit.<span style="color: #006633;">HEARTS</span><span style="color: #339933;">:</span>
        <span style="color: #666666; font-style: italic;">// do hearts processing</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">case</span> Suit.<span style="color: #006633;">CLUBS</span><span style="color: #339933;">:</span>
        <span style="color: #666666; font-style: italic;">// do clubs processing</span>
        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Keep in mind that an enum can also take on other properties of a class. Instance variables and methods can still be defined in the enum. Since the only creation of enum values are done inside of the enum itself, any instance variables must be initialized in the constructor. For example, assume we wanted a display name for each suit. The following changes would support this addition:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">enum</span> Suit <span style="color: #009900;">&#123;</span>
    HEARTS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hearts&quot;</span><span style="color: #009900;">&#41;</span>,
    DIAMONDS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Diamonds&quot;</span><span style="color: #009900;">&#41;</span>,
    CLUBS<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Clubs),
    SPADES(&quot;</span>Spades<span style="color: #0000ff;">&quot;);
&nbsp;
    private String name;
&nbsp;
    private Suit(String n) {
        name = n;
    }
&nbsp;
    public String getName() {
        return name;
    }
}</span></pre></td></tr></table></div>

<p>Given the above changes, the public methods can be called on the enum values as if they were any other object::</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>Suit.<span style="color: #006633;">HEARTS</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>For another example, check out <a href="http://codeturtle.svn.sourceforge.net/viewvc/codeturtle/src/com/novasurv/turtle/frontend/swing/grades/GradeColumn.java?revision=188&#038;view=markup" target="new">the enum for each column in the grades table in CodeTurtle.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2009/02/09/java-enum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Sample: File Chooser Demo v1.0</title>
		<link>http://noopenblockers.com/2008/11/02/code-sample-file-chooser-demo/</link>
		<comments>http://noopenblockers.com/2008/11/02/code-sample-file-chooser-demo/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 03:41:47 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://notebook.novasurv.com/?p=148</guid>
		<description><![CDATA[Swing provides built in support for a file chooser dialog. It&#8217;s a huge time saver to not have to implement all of the pieces involved, the component is pretty well flushed out, and it&#8217;s easy to use.
The attached code is released under the GNU General Public License.
Click here to download the source.
]]></description>
			<content:encoded><![CDATA[<p>Swing provides built in support for a file chooser dialog. It&#8217;s a huge time saver to not have to implement all of the pieces involved, the component is pretty well flushed out, and it&#8217;s easy to use.</p>
<p>The attached code is released under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt" target="new">GNU General Public License</a>.</p>
<p><a href="/wp-content/uploads/code/file-chooser-demo.zip">Click here to download the source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2008/11/02/code-sample-file-chooser-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Sample: Dialog Boxes Demo v1.0</title>
		<link>http://noopenblockers.com/2008/11/01/code-sample-dialog-boxes-demo/</link>
		<comments>http://noopenblockers.com/2008/11/01/code-sample-dialog-boxes-demo/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 21:49:41 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://notebook.novasurv.com/?p=146</guid>
		<description><![CDATA[Swing includes some quick and powerful methods to facilitate the display of dialog boxes. These dialog boxes can be customized with a message, title, icon, and even the choice of buttons to display to the user. Additionally, the dialog boxes can even request user input in the form of a text field or drop-down box. [...]]]></description>
			<content:encoded><![CDATA[<p>Swing includes some quick and powerful methods to facilitate the display of dialog boxes. These dialog boxes can be customized with a message, title, icon, and even the choice of buttons to display to the user. Additionally, the dialog boxes can even request user input in the form of a text field or drop-down box. The boxes are modal, which means that their parent frame cannot be accessed until the dialog box is addressed. </p>
<p>This code sample demonstrates a few different possibilities for working with dialog boxes. When running the application, a simple frame will appear with a button for each example. Pressing the button will result in its corresponding dialog box being displayed. In certain cases, logging information will be written to standard output to reflect the user&#8217;s interaction with a dialog box.</p>
<p>The attached code is released under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt" target="new">GNU General Public License</a>.</p>
<p><a href="/wp-content/uploads/code/dialog-boxes-demo.zip">Click here to download the source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2008/11/01/code-sample-dialog-boxes-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Sample: Swing Components Demo v1.0</title>
		<link>http://noopenblockers.com/2008/10/05/code-sample-swing-components-demo/</link>
		<comments>http://noopenblockers.com/2008/10/05/code-sample-swing-components-demo/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 03:24:08 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://notebook.novasurv.com/?p=103</guid>
		<description><![CDATA[The Swing Components Demo displays examples of a number of standard UI components. A number of the components use some form of listener to output tracking information to standard output.
Be sure to take a look at the code as this sample is intended as a reference or tutorial. A number of configuration settings for each [...]]]></description>
			<content:encoded><![CDATA[<p>The Swing Components Demo displays examples of a number of standard UI components. A number of the components use some form of listener to output tracking information to standard output.</p>
<p>Be sure to take a look at the code as this sample is intended as a reference or tutorial. A number of configuration settings for each component are indicated in the code itself. Feel free to play around with these settings to see their effects on the UI.</p>
<p>The main layout of the components uses a GridBagLayout. A full description of how to use GridBagLayout is outside the scope of this sample. There is still value in looking over its use, however the in code documentation on its usage is intentionally admitted for now. I&#8217;ll probably do a specific sample dedicated to GridBagLayout and its usage.</p>
<p>The attached code is released under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt" target="new">GNU General Public License</a>.</p>
<p><a href="/wp-content/uploads/code/swing-components-demo.zip">Click here to download the source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2008/10/05/code-sample-swing-components-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Sample: Event Listeners (Named Inner Classes) v1.0</title>
		<link>http://noopenblockers.com/2008/10/04/code-sample-event-listeners-named-inner-classes-v10/</link>
		<comments>http://noopenblockers.com/2008/10/04/code-sample-event-listeners-named-inner-classes-v10/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 16:58:02 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://notebook.novasurv.com/?p=101</guid>
		<description><![CDATA[I&#8217;ve already posted a sample Swing application that used anonymous inner classes to define all of the needed event listeners. This sample is a port of the same functionality, however all of the anonymous inner classes have been replaced with named inner classes.
Named inner classes are defined just like any other class, however they are [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve <a href="/2008/10/02/code-sample-event-listeners-anonymous-inner-classes-v10/">already posted</a> a sample Swing application that used anonymous inner classes to define all of the needed event listeners. This sample is a port of the same functionality, however all of the anonymous inner classes have been replaced with named inner classes.</p>
<p>Named inner classes are defined just like any other class, however they are defined inside of another class (this is compared to anonymous inner classes that are defined at object instantiation time). There are specific rules on where and how they can be accessed outside of the class that are outside of the scope of this post.</p>
<p>One benefit to named inner classes is that they can be instantiated more than once, as compared to the single instantiation of anonymous inner classes. Additionally, as named inner classes function just like other classes, they can implement more than one interface. This code sample demonstrates using one implementation to function as multiple listener types.</p>
<p>The attached code is released under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt" target="new">GNU General Public License</a>.</p>
<p><a href="/wp-content/uploads/code/event-listeners-named.zip">Click here to download the source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2008/10/04/code-sample-event-listeners-named-inner-classes-v10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Sample: Event Listeners (Anonymous Inner Classes) v1.0</title>
		<link>http://noopenblockers.com/2008/10/02/code-sample-event-listeners-anonymous-inner-classes-v10/</link>
		<comments>http://noopenblockers.com/2008/10/02/code-sample-event-listeners-anonymous-inner-classes-v10/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 03:18:44 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://notebook.novasurv.com/?p=93</guid>
		<description><![CDATA[In class tonight, we discussed a number of ways to implement the event listener interfaces that drive Swing. One such approach is through the use of anonymous inner classes.
Anonymous inner classes are called as such because they do not have a name. They are instantiated at the same time the class is defined. The code [...]]]></description>
			<content:encoded><![CDATA[<p>In class tonight, we discussed a number of ways to implement the event listener interfaces that drive Swing. One such approach is through the use of anonymous inner classes.</p>
<p>Anonymous inner classes are called as such because they do not have a name. They are instantiated at the same time the class is defined. The code in this sample includes comments describing the syntax of how these types of inner classes are defined, so be sure to look at the source in addition to compiling and running the application.</p>
<p>Going forward, I&#8217;m going to post another sample of this application, ported to use named inner classes for the implementation instead of anonymous inner classes.</p>
<p>The attached code is released under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt" target="new">GNU General Public License</a>.</p>
<p><a href="/wp-content/uploads/code/event-listeners-anon.zip">Click here to download the source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2008/10/02/code-sample-event-listeners-anonymous-inner-classes-v10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
