<?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>Conor's Blog &#187; Languages</title>
	<atom:link href="http://blog.macaoidh.name/category/languages/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.macaoidh.name</link>
	<description>PHP, Music, Linux</description>
	<lastBuildDate>Mon, 05 Jul 2010 13:25:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>OS X: Audio Alerts for PHP Errors</title>
		<link>http://blog.macaoidh.name/2010/06/22/os-x-audio-alerts-for-php-errors/</link>
		<comments>http://blog.macaoidh.name/2010/06/22/os-x-audio-alerts-for-php-errors/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 16:14:41 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Apple Script]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=312</guid>
		<description><![CDATA[Kae posted today about tackling this problem under Linux, but I&#8217;ve found that it&#8217;s quite a different task under OS X. Anyway here is how it&#8217;s done: First you need to download the swatch package from here. If you haven&#8217;t done it before you will have to set up cpan and it&#8217;s a lengthy process. [...]]]></description>
			<content:encoded><![CDATA[<p>Kae <a href="http://verens.com/2010/06/22/audio-alerts-for-php-errors">posted</a> today about tackling this problem under Linux, but I&#8217;ve found that it&#8217;s quite a different task under OS X. Anyway here is how it&#8217;s done:</p>
<p>First you need to download the swatch package from <a href="http://sourceforge.net/projects/swatch/">here</a>.</p>
<p>If you haven&#8217;t done it before you will have to set up cpan and it&#8217;s a lengthy process. Run cpan in the terminal. It&#8217;s safe to say yes to all the options. Once it&#8217;s installed you need to add some perl modules. In the cpan prompt add the following modules:</p>
<pre class="brush:bash">install Date::Calc
install Date::Format
install Date::Manip
install File::Tail
</pre>
<p>That&#8217;s the perl part finished anyway. Now change to the swatch directory and compile:</p>
<pre class="brush:bash">perl Makefile.pl
make
make install</pre>
<p>Ok swatch should be installed now. So set up the configuration file: <code>vim ~/.swatchrc</code> Add the following lines to the file:</p>
<pre class="brush:bash">watchfor /PHP Parse error|PHP Fatal error/
bell 3
</pre>
<p>Save and return to the command line. Now to add swatch (and also optionally apache and mysql) as a startup item do as follows. Create a new directory named StartUpItems, then create the following files so your setup should look like this:</p>
<pre>StartUpItems
StartUpItems/StartUpItems (a file with no extention)
StartUpItems/StartupParameters.plist
</pre>
<p>Now add the following contents to StartupParameters.plist:</p>
<pre class="brush:xml">
< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
    <dict>
        <key>Description</key>
        <string>Various Startup commands including Swatch, Apache and MySQL.</string>

        <key>OrderPreference</key>
        <string>Late</string>

        <key>Provides</key>
        <array>
                <string>Starts up Swatch, Apache and MySQL.</string>
        </array>
    </dict>
</plist>
</pre>
<p>That&#8217;s just a file required by OS X to recognise the startup item, don&#8217;t worry to much about it. Now to the StartUpCommands file which is a bash script:</p>
<pre class="brush:bash">#!/bin/bash
. /etc/rc.common

StartService(){
        ConsoleMessage "Starting Apache, MySQL and Swatch"
        apachectl start
        /usr/local/mysql/support-files/mysql.server start
        /opt/local/bin/swatch --daemon --config-file=/Users/conormacaoidh/.swatchrc --tail-file=/var/log/php/php-error_log --pid-file=/var/run/swatch-httpd-errors.pid
}

StopService(){
        ConsoleMessage "Stopping Apache, MySQL and Swatch"
        PID=`cat /var/run/swatch-httpd-errors.pid`
        kill -9 $PID
        apachectl stop
        /usr/local/mysql/support-files/mysql.server stop
}

RestartService(){
        RunService stop
        RunService start
}

RunService "$1"
</pre>
<p>The file</p>
<pre>/etc/rc.common</pre>
<p>is provided by apple and makes the process a lot easier, though it is not needed. The lines in StartService and StopService do the opposite of each other but are very similar. You may need to change the apache and mysql start/stop commands according to your own setup. If you are using MAMP this file will start apache and mysql:</p>
<pre>/Applications/MAMP/bin/start.sh</pre>
<p>As for the swatch line you will obviously have to change the config file location and the php error log location to what&#8217;s appropriate on your machine.</p>
<p>And that&#8217;s it really. Then copy the items to the correct directory for OS X to recognise them:</p>
<pre class="brush:bash">sudo cp -R StartUpCommands /Library/StartUpItems
</pre>
<p>It is vital that you change the permissions or else the startup item simply won&#8217;t be executed:</p>
<pre class="brush:bash">sudo chown -R root /Library/StartUpItems/StartUpCommands
sudo chgrp -R wheel /Library/StartUpItems/StartUpCommands
sudo chmod -R 755 /Library/StartUpItems/StartUpCommands
</pre>
<p>That&#8217;s it. You can test the configuration by running SystemStarter -n -D which will emulate what happens when the computer starts, it is useful for de-bugging.</p>
<p>So restart you computer, load a php file with an error in it and your machine will beep thrice!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2010/06/22/os-x-audio-alerts-for-php-errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Drawing Squares</title>
		<link>http://blog.macaoidh.name/2009/12/05/java-drawing-squares/</link>
		<comments>http://blog.macaoidh.name/2009/12/05/java-drawing-squares/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 03:28:07 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[icsp]]></category>
		<category><![CDATA[reges]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[shape]]></category>
		<category><![CDATA[squares]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=284</guid>
		<description><![CDATA[This weeks ICSP assignment was to write a program which draws squares. The task was to draw squares from a set list in an array, but I opted rather to accept a command line argument in my script. To write this I had to delve back into regular expression, which I hate because I don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>This weeks ICSP assignment was to write a program which draws squares. The task was to draw squares from a set list in an array, but I opted rather to accept a command line argument in my script. To write this I had to delve back into regular expression, which I hate because I don&#8217;t understand!</p>
<p>The program source is below. You should execute the program from the command line giving the with and height of the square you wish to draw, for example:</p>
<pre class="brush: bash">
java Squares 4x4
</pre>
<p>And the code:</p>
<pre class="brush: java">
import java.lang.String;
import java.util.regex.*;

public class Squares{
        public int dimensions[];

        public Squares(String[] args){
                if(args.length==1){
                        Pattern form=Pattern.compile("^\\S+x\\S+$");
                        Matcher fit=form.matcher(args[0]);
                        if(fit.matches()){
                                try{
                                        String[] dims=args[0].split("x");
                                        int width=Integer.parseInt(dims[0]);
                                        int height=Integer.parseInt(dims[1]);
                                        this.dimensions=new int[] {width,height};
                                }
                                catch(NumberFormatException e){
                                        System.err.println("Argument must be a string, width by height, in the form 6x6");
                                        System.exit(1);
                                }
                        }
                        else{
                                System.out.println("Argument must be a string, width by height, in the form 6x6");
                                System.exit(1);
                        }
                }
                else{
                        System.err.println("Please supply an argument, which must be a string, width by height, in the form 6x6");
                        System.exit(0);
                }
        }

        public String draw(){
                int i;
                int z;
                int width=this.dimensions[0];
                int height=this.dimensions[1];
                String square="";

                for(i=0;i&lt;height ;i++){
                        for(z=0;z&lt;width;z++){
                                if((i==0||i==height-1)&#038;&#038;(z==0||z==width-1))
                                        square+="+";
                                else if(z==0||z==width-1)
                                        square+="|";
                                else if((i==0||i==height-1))
                                        square+="-";
                                else
                                        square+=" ";
                        }
                        square+="\n";
                }

                return square;
        }

        public static void main(String[] args){
                Squares square=new Squares(args);
                String draw=square.draw();
                System.out.println(draw);
        }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/12/05/java-drawing-squares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Calculate Taxi Fares</title>
		<link>http://blog.macaoidh.name/2009/12/02/java-calculate-taxi-fares/</link>
		<comments>http://blog.macaoidh.name/2009/12/02/java-calculate-taxi-fares/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 00:21:25 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[fare]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Scratch]]></category>
		<category><![CDATA[taxi]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=281</guid>
		<description><![CDATA[This week my ICSP assignment was to calculate taxi fares. The task was: Using the fare table write a program that calculates the fares and test if it is correct. Upload your .java or your Scratch file. A template file for java will be provided. (Hint, only the boundary values needs to be tested. The [...]]]></description>
			<content:encoded><![CDATA[<p>This week my ICSP assignment was to calculate taxi fares. The task was:</p>
<blockquote><p>Using the fare table write a program that calculates the fares and test if it is correct. Upload your .java or your Scratch file. A template file for java will be provided. (Hint, only the boundary values needs to be tested. The fare table is also presented in the slides. The compile command for java should be &#8220;javac TaxiRide.java&#8221;)</p>
<table border="0">
<tbody>
<tr>
<th colspan="2">Fare table</th>
</tr>
<tr>
<th>Distance (km)</th>
<th>Cost (€)</th>
</tr>
<tr>
<td>&gt;50</td>
<td>30</td>
</tr>
<tr>
<td>50-100</td>
<td>25, plus 9 for each km &gt; 50</td>
</tr>
<tr>
<td>100 &#8211; 2000</td>
<td>190, plus 8 for each km &gt; 100</td>
</tr>
<tr>
<td>&gt; 2000</td>
<td>1800</td>
</tr>
</tbody>
</table>
</blockquote>
<p>It wasn&#8217;t the hardest task. The only thing that confused me was the Java switch syntax. In PHP you can have conditions in a switch statement such as:</p>
<pre class="brush:php">
&lt;?php
switch($num){
        case ($num&lt;10):
                // blah
        break;
        case ($num&lt;100):
                // blah
        break;
        default:
                //blah
?&gt;
</pre>
<p>I couldn&#8217;t get Java to accept anything other than a value for the variable bring switched. So I did it the old-fashioned way! My code is below&#8230;</p>
<pre class="brush:java">
public class TaxiRide{
        public int distance=0;

        public TaxiRide(String arg){
                try{
                        int distance=Integer.parseInt(arg);
                        this.distance=distance;
                }
                catch(NumberFormatException e){
                        System.err.println("Arguement must be an integer representing the distance traveled");
                        System.exit(1);
                }
        }

        public int calculateFare(){
                int distance=this.distance;
                int fare=0;
                int i=0;
                if(distance&lt;50){
                        return 30;
                }
                if(distance%lt;100){
                        fare=25;
                        distance-=50;
                        for(i=0;i&lt;distance;i++){
                                fare+=9;
                        }
                        return fare;
                }
                if(distance&lt;2000){
                        fare=190;
                        distance-=100;
                        for(i=0;i&lt;distance;i++){
                                fare+=8;
                        }
                        return fare;
                }
                return 1800;
        }

        public static void main(String[] args){
                TaxiRide taxiRide = new TaxiRide(args[0]);
                int fare=taxiRide.calculateFare();
                System.out.println("The fare is: "+fare+" euro for traveling "+taxiRide.distance+"kM\n Thank you\n");
        }
}
</pre>
<p>I feel i am learning a lot from this course. Lately I have been experimenting in a few different languages. I added a bit to the Scratch Linux installer, written in Perl, so that it added an icon in the applications menu during installation. I&#8217;ve also been messing around with bash, trying to automate some of my most common commands&#8230; was thinking of writing a small bash script that backed up my data when my external hard drive is plugged in, similar to Time Machine on OSX.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/12/02/java-calculate-taxi-fares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Project Euler Multiples</title>
		<link>http://blog.macaoidh.name/2009/11/21/java-project-euler-multiples/</link>
		<comments>http://blog.macaoidh.name/2009/11/21/java-project-euler-multiples/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 18:32:05 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[1000]]></category>
		<category><![CDATA[3]]></category>
		<category><![CDATA[5]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[icsp]]></category>
		<category><![CDATA[multiples]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[project euler]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=272</guid>
		<description><![CDATA[This weeks ICSP assignment was one of the Project Euler challenges. Here is the task: This weeks Bonus Task is to solve the First Problem using Java: &#8220;If we list all the natural numbers below 10 that are multiples of 3 or 5, we * get 3, 5, 6 and 9. The sum of these [...]]]></description>
			<content:encoded><![CDATA[<p>This weeks ICSP assignment was one of the <a href="http://projecteuler.net/index.php?section=about">Project Euler</a> challenges. Here is the task:</p>
<p>This weeks Bonus Task is to solve the First Problem using Java:<br />
&#8220;If we list all the natural numbers below 10 that are multiples of 3<br />
or 5, we * get 3, 5, 6 and 9. The sum of these multiples is 23.</p>
<p>Find the sum of all the multiples of 3 or 5 below 1000.&#8221;</p>
<p>In the code below, I have achieved this objective and also expanded on it. My program allows you to pass on two multiples and a max integer value to the program for which to calculate the results. You can execute:</p>
<pre class="brush: java">java Multiples 3 5 1000</pre>
<p>That command will find the sum of multiples of 3 and 5 below 1000, as stated in the task. You can also change the values to calculate different sums. The code for Multiples.java is below:</p>
<pre class="brush: java">/*
 * Developer:   Conor Mac Aoidh
 * Homepage:    http://blog.macaoidh.name/2009/11/21/java-project-euler-multiples/
 */

public class Multiples{
        public static void main(String[] args){
                Multiples multiples=new Multiples();
                int one=0;
                int two=0;
                int max=0;
                if(args.length==3){
                        try{
                                one=Integer.parseInt(args[0]);
                                two=Integer.parseInt(args[1]);
                                max=Integer.parseInt(args[2]);
                        }
                        catch(NumberFormatException e){
                                System.err.println("Argument must be an integer");
                                System.exit(1);
                        }
                }
                else
                        System.out.println("You must supply integers in the format:\n multiple_one multiple_two max_integer");

                int sum=multiples.sum(one,two,max);

                System.out.println("Find the sum of all the multiples of "+one+" or "+two+" below "+max);
                System.out.println("Sum:"+sum);
        }

        public int sum(int one,int two,int max){
                int i=0;
                int sum=0;
                for(i=0;i&lt;max ;i++){
                        if(i % one==0)
                                sum=sum+i;
                        if(i % two==0)
                                sum=sum+i;
                }
                return sum;
        }
}</pre>
<p>Simple as that!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/11/21/java-project-euler-multiples/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Java Visual Hello World Popup</title>
		<link>http://blog.macaoidh.name/2009/11/15/java-visual-hello-world-popup/</link>
		<comments>http://blog.macaoidh.name/2009/11/15/java-visual-hello-world-popup/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 13:07:19 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[add text to jframe]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[jbutton]]></category>
		<category><![CDATA[jframe]]></category>
		<category><![CDATA[jpanel]]></category>
		<category><![CDATA[popup]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[visual]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=261</guid>
		<description><![CDATA[I spent yesterday going a bit deeper into Java with one of my lecturers. I decided to try and write a more complicated hello world app. It&#8217;s quite simple really once you get around the strict OOP and different syntax&#8230; This is how I did it: First you need to import some of the java [...]]]></description>
			<content:encoded><![CDATA[<p>I spent yesterday going a bit deeper into Java with one of my lecturers. I decided to try and write a more complicated hello world app. It&#8217;s quite simple really once you get around the strict OOP and different syntax&#8230; This is how I did it:</p>
<p>First you need to import some of the java libraries that we will be using:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
</pre>
<p>Then add the class, Popup. Make sure to name the file Popup.java</p>
<pre class="brush: java">
public class Popup{
private JFrame frame=new JFrame("Hello!");
private JPanel panel=new JPanel();
private JButton button=new JButton("Say Hello");
private JLabel label=new JLabel("Click the button to say hello...",SwingConstants.CENTER);
private ButtonListener buttonListener=new ButtonListener();
</pre>
<p>What that actually means is create a new instance of JFrame, JPanel, JButton and JLabel and store them in the frame,panel, button and label variables. As for the ButtonListener, we will deal with that later. Now we will deal with the launchFrame function which does what it says on the tin &#8211; launches the frame! Basically it just connects all of the pieces of information stored into the variables above and displays them together.</p>
<pre class="brush: java">
public void launchFrame(){
int height=400, width=600;
frame.setSize(width,height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
</pre>
<p>Above we create two new integers which store the width and height of our frame. The next line sets the variables to the frame size. The final line tells the Java application to close when the window, or JFrame, is closed. Now that we have the configuration out of the way we can move on to adding the variables to the frame.</p>
<pre class="brush: java">
frame.getContentPane().add(label,BorderLayout.CENTER);
panel.add(button);
frame.getContentPane().add(panel,BorderLayout.WEST);
button.addActionListener(buttonListener);
frame.setVisible(true);
}
</pre>
<p>The code above adds the label to the frame, then adds the button to the panel and then the panel to the frame. Once again disregard the button.addAction.. line for now. The final line simply sets the frame to visible so we can see it.</p>
<p>Now that we have the frame settled, we need to add our essential main function to start up the execution:</p>
<pre class="brush: java">
public static void main(String args[]){
Popup popup=new Popup();
popup.launchFrame();
}
}
</pre>
<p>This code basically creates an instance of our class, Popup and then executes the function launchFrame which we have created in that class.</p>
<p>That&#8217;s the guts of it, but now we need to talk about these lines:</p>
<pre class="brush: java">
private ButtonListener buttonListener=new ButtonListener();</pre>
<pre class="brush: java">
 public void launchFrame(){
....
button.addActionListener(buttonListener);
</pre>
<p>Basically we have previously created a button, but these lines define what happens when the button is pressed. The second line of code tells the machine to listen out for the clicking of the button, and when that happens to execute the variable buttonListener. We have created the variable buttonListener, which creates a new instance of the ButtonListener class which we have yet to create.</p>
<p>That is the next step, to create that class. Create a new file called ButtonListener.java and add this code:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;</pre>
<pre class="brush: java">
public class ButtonListener implements ActionListener{
</pre>
<p>The first four lines import the libraries that we are using. The final line is important. It states that our class, ButtonListener is implementing the ActionListener class. Below is the content of our new class:</p>
<pre class="brush: java">
private JFrame pressed=new JFrame("Hello World!");</pre>
<pre class="brush: java">
public void actionPerformed(ActionEvent actionEvent){
</pre>
<p>First, we create a new JFrame for our popup just like we did in the other file. The function actionPerformed is  a function from the ActionListener class that we are implementing. The parameters for the function are predefined so we need them. The rest of the code is very similar to the previous code so I won&#8217;t explain it in depth. Basically it just configures the new frame, adds the label and then displays it:</p>
<pre class="brush: java">
int height=160, width=200;
pressed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel pressedtext=new JLabel("Hello World!",SwingConstants.CENTER);
pressed.getContentPane().add(pressedtext,BorderLayout.CENTER);
pressed.setSize(width,height);
pressed.setVisible(true);
}</pre>
<p>Save that file and then compile both files by executing:</p>
<pre class="brush: bash">
javac ButtonListener.java Popup.java
</pre>
<p>Now if you run the program you should see a nice visual dialogue:</p>
<pre class="brush: bash">
java Popup
</pre>
<p>You can download a jar archive of the program <a href="http://files.macaoidh.name/Download/Java-Popup-Hello-World">here</a>.</p>
<p>The full code is below. Popup.java:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class Popup{
        private JFrame frame=new JFrame("Hello!");
        private JPanel panel=new JPanel();
        private JButton button=new JButton("Say Hello");
        private JLabel label=new JLabel("Click the button to say hello...",SwingConstants.CENTER);
        private ButtonListener buttonListener=new ButtonListener();

        public void launchFrame(){
                int height=400, width=600;
                frame.setSize(width,height);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.getContentPane().add(label,BorderLayout.CENTER);
                panel.add(button);
                frame.getContentPane().add(panel,BorderLayout.WEST);
                button.addActionListener(buttonListener);
                frame.setVisible(true);
        }

        public static void main(String args[]){
                Popup popup=new Popup();
                popup.launchFrame();
        }
}
</pre>
<p>ButtonListener.java:</p>
<pre class="brush: java">
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class ButtonListener implements ActionListener{
        private JFrame pressed=new JFrame("Hello World!");

        public void actionPerformed(ActionEvent actionEvent){
                int height=160, width=200;
                pressed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JLabel pressedtext=new JLabel("Hello World!",SwingConstants.CENTER);
                pressed.getContentPane().add(pressedtext,BorderLayout.CENTER);
                pressed.setSize(width,height);
                pressed.setVisible(true);
        }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/11/15/java-visual-hello-world-popup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Capture the Flag Part 3</title>
		<link>http://blog.macaoidh.name/2009/11/07/capture-the-flag-part-3/</link>
		<comments>http://blog.macaoidh.name/2009/11/07/capture-the-flag-part-3/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 20:48:38 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[blue]]></category>
		<category><![CDATA[capture the flag]]></category>
		<category><![CDATA[part 3]]></category>
		<category><![CDATA[players]]></category>
		<category><![CDATA[red]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=258</guid>
		<description><![CDATA[I have been flat out recently with school and work and this ICSP thing. Well anyway I have had no time to do any furasta or any independent spur of the moment programing! It&#8217;s driving me crazy, but hey, it&#8217;s all over in just over 6 months&#8230;. Capture the Flag Part 3 This time I [...]]]></description>
			<content:encoded><![CDATA[<p>I have been flat out recently with school and work and this ICSP thing. Well anyway I have had no time to do any furasta or any independent spur of the moment programing! It&#8217;s driving me crazy, but hey, it&#8217;s all over in just over 6 months&#8230;.</p>
<p>Capture the Flag Part 3</p>
<p>This time I have deviated from the rules a wee bit. The red player is controlled by the CPU, while the user controls the blue player. Once again the objective is to capture the red flag and return it to your blue base. If you bump into a player who has a flag then flag gets returned to it&#8217;s base.</p>
<p>The players, and flags have three random starting positions each. I have re-written this example from scratch, not using any of the code from part one or two. I am happy with the code this time, and have done my best to make it effective.</p>
<p>The red player has two modes, aggressive and defensive. When the game starts the red player attempts to capture the flag and return it to it&#8217;s red base automatically. If at any point the blue player acquires his flag the red player will go into defensive mode and attempt to recover his flag.</p>
<p>To throw a spanner in the works I have added a BOOST and an obstacle. The boost can gradually makes the player who absorbs it smaller to increase evasive skills. It also makes the player a lot faster. The obstacle has two modes. If you bump into it the wrong way, you will simply bump off it. If you follow the arrows through the obstacle with your player then you will receive a big speed bonus. Both these items will prove vital in winning against the red player, who moves faster than the blue one.</p>
<p>Controls</p>
<p>Up Key &#8211; Move Up<br />
Down Key &#8211; Move Down<br />
Left Key &#8211; Move Left<br />
Right Key &#8211; Move Right</p>
<p><applet id='ProjectApplet' style='display:block' code='ScratchApplet' codebase='http://scratch.mit.edu/static/misc' archive='ScratchApplet.jar' height='387' width='482'>
<param name='project' value='../../static/projects/ConorMacAoidh/749759.sb'></param></applet> <a href='http://scratch.mit.edu/projects/ConorMacAoidh/749759'>Learn more about this project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/11/07/capture-the-flag-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ICSP Week One Assignment</title>
		<link>http://blog.macaoidh.name/2009/10/25/icsp-week-one-assignment/</link>
		<comments>http://blog.macaoidh.name/2009/10/25/icsp-week-one-assignment/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 20:38:05 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[caputre the flag]]></category>
		<category><![CDATA[icsp]]></category>
		<category><![CDATA[Scratch]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=250</guid>
		<description><![CDATA[I started a course in UCD last week called &#8220;Introduction to Computer Science and Programing&#8221;, or ICSP. It&#8217;s gonna be going on for three months and then I will have a big exam which I will probably fail! The whole course centers around the use of Java, I&#8217;m not sure yet if we are going [...]]]></description>
			<content:encoded><![CDATA[<p>I started a course in UCD last week called &#8220;Introduction to Computer Science and Programing&#8221;, or <a href="http://www.csi.ucd.ie/content/introduction-computer-science-and-programming-icsp2009">ICSP</a>. It&#8217;s gonna be going on for three months and then I will have a big exam which I will probably fail!</p>
<p>The whole course centers around the use of Java, I&#8217;m not sure yet if we are going to be using anything else. We haven&#8217;t actually even started with Java yet, but we are using this program called <a href="http://scratch.mit.edu/">Scratch</a> to program our Java for us! I wouldn&#8217;t say that it is the Dream-weaver of Java, far from it. In fact I think that it is a great method of getting into Java. It has a set of preconfigured code which you can arrange into blocks, which then run &#8211; quite similar to the source of Java actually except simplified. It also eliminates the need for compiling.</p>
<p>Last week I went to my first &#8220;lecture&#8221; which was good enough, but I learned something valuable that day; computer hardware is not the road that I want to go down! I didn&#8217;t really enjoy the hardware aspect of the day but when it came to the Scratch lessons I was flying! For our first assignment we had to write a game in Scratch, which is essentially it&#8217;s own unique programing language. The game is called &#8220;Capture the Flag&#8221;. I was actually flat out all week and didn&#8217;t get a chance to start work on it until today, which is coincidentally the deadline for it&#8217;s completion! I spent about three hours making the game, here&#8217;s the manual and the game:</p>
<h3>Capture The Flag</h3>
<p><strong>Overview</strong><br />
Capture the flag is a simple two player game which involves stealing the flag from the opposite colours corner.</p>
<p><strong>Controls</strong><br />
Blue Player<br />
Up Arrow Key = Move Up<br />
Down Arrow Key = Move Down<br />
Left Arrow Key = Move Left<br />
Right Arrow Key = Move Right</p>
<p>Red Player<br />
W Key = Move Up<br />
S Key = Move Down<br />
A Key = Move Left<br />
D Key = Move Right</p>
<p><strong>Rules</strong><br />
To gain a point a player must capture the opposite colour flag and return it to their base (the starting point).</p>
<p>If a player is in possession of a flag and his opponent touches him the flag is returned to it&#8217;s base and the player to his base.</p>
<p>To win a player must gain three points.</p>
<p><strong>Faults</strong><br />
The one fault with the game is that, at least on my computer, when one player is using the keyboard to move the other player cannot move simultaneously. Although this is a fault it does also make the game a bit more interesting because the players have to fight even to move!</p>
<p><applet id='ProjectApplet' style='display:block' code='ScratchApplet' codebase='http://scratch.mit.edu/static/misc' archive='ScratchApplet.jar' height='387' width='482'>
<param name='project' value='../../static/projects/ConorMacAoidh/732336.sb'></param></applet> <a href='http://scratch.mit.edu/projects/ConorMacAoidh/732336'>Learn more about this project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/10/25/icsp-week-one-assignment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One Year of macaoidh.name</title>
		<link>http://blog.macaoidh.name/2009/09/22/one-year-of-macaoidh-name/</link>
		<comments>http://blog.macaoidh.name/2009/09/22/one-year-of-macaoidh-name/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 22:35:42 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Me]]></category>
		<category><![CDATA[My Blog]]></category>
		<category><![CDATA[The Dominican Affair]]></category>
		<category><![CDATA[icsp]]></category>
		<category><![CDATA[java.facebook application]]></category>
		<category><![CDATA[macaoidh.name anniversary]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=237</guid>
		<description><![CDATA[Would you believe it? It&#8217;s the first anniversary of my Blog! I have officially been ranting about shite for a whole year! Anyway to celebrate the birthday of my Blog I decided to do it up a wee bit. I added a nice wee sidebar to my theme, which I am actually thinking of releasing [...]]]></description>
			<content:encoded><![CDATA[<p>Would you believe it? It&#8217;s the first anniversary of my Blog! I have officially been ranting about shite for a whole year!</p>
<p>Anyway to celebrate the birthday of my Blog I decided to do it up a wee bit. I added a nice wee sidebar to my theme, which I am actually thinking of releasing at some stage in the near future. Also I added a new download manager to http://files.macaoidh.name . It is very useful; it keeps track of how many people are downloading what. Hopefully in the future it will give me an idea of what people that view my blog like and don&#8217;t like. I will actually have to go over all my previous posts and make sure that the download links are correct considering there was a big change in the link format.</p>
<p>The only real reason I wrote the thing is because someone has commissioned me to do something similar, starting next week. But the commissioned work will be a bit more complete and stuff. So feel free to try and hack my system. I don&#8217;t want to find faults when I&#8217;m finished writing it and then have to go back&#8230; The manager also serves as a very useful tool for me. I have included an admin area in which I can log in, upload files and choose to store them, make them available for download or even to download + password protect them! This feature will no doubt come in handy, I like to think of it as my personal, non-user-information-gathering, version of Google Docs!</p>
<p>What else has been happening recently&#8230; ooh I am in the process of making/releasing an album with The Dominican Affair. It is called Stealing the Ceiling. We have our last mixing session this weekend and hope to have it available on piratebay towards the end of October! It will also be available to purchase or download at http://www.holygrailrecords.com</p>
<p>Just thought I&#8217;d mention that 6th year is terribly shit. I can manage to squeze about 2 hours of programing in thrice a week. Also I am doing an<a href="http://www.csi.ucd.ie/icsp"> Introduction to Computer Science Programing </a>course in UCD over the next few months just to prepare me for college and to make sure that I actually want to study Computer Science! It will be good craic to learn Java at that course; I plan to make a facebook application/game when I have learned Java and base it in Monaghan.</p>
<p>Oghgbjkc damn! I just realised that I still haven&#8217;t renewed my macaoidh.name subscription! Better get to it&#8230; three days left&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/09/22/one-year-of-macaoidh-name/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Webme Plugins</title>
		<link>http://blog.macaoidh.name/2009/07/29/webme-plugins/</link>
		<comments>http://blog.macaoidh.name/2009/07/29/webme-plugins/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 22:26:26 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Projects]]></category>
		<category><![CDATA[webme]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=233</guid>
		<description><![CDATA[I have been doing a bit of work on some Webme plugins recently. All of the plugins I have been working on are available for download in the webworks-webme SVN and live on the Monaghan Medical Centre website. Dynamic Search Plugin The dynamic search plugin enables you to search different sections of your website dynamically. [...]]]></description>
			<content:encoded><![CDATA[<p>I have been doing a bit of work on some <a href="http://webme.eu">Webme</a> plugins recently. All of the plugins I have been working on are available for download in the <a href="http://code.google.com/p/webworks-webme/source/checkout">webworks-webme SVN</a> and live on the <a href="http://www.monaghanmedicalcentre.ie">Monaghan Medical Centre</a> website.</p>
<h3>Dynamic Search Plugin</h3>
<p>The dynamic search plugin enables you to search different sections of your website dynamically. You can choose between searching Site Wide or a selection of categories. You can add catagories in the admin area. A catagory must be a pagename and the plugin will search that page and all sub pages. The plugin also keeps a record of the most popular searches and displays a link to them on the main search page.</p>
<p>The entire plugin is written in both PHP and jQuery. The PHP end acts as a backup for the javascript end. It also allows you to use your own search form to display results from this plugin, as I have done on the MMC site.</p>
<p><a title="Download Dynamic Search Plugin" href="http://files.macaoidh.name/webme/dynamic-search-0.2.zip">Download</a> | <a href="http://www.monaghanmedicalcentre.ie/Search">View Live</a></p>
<h3>Mailing List Plugin</h3>
<p>This is a plugin that I released a while ago but I have made a few changes recently. Previously there was PHP form validation which replaced the form itself if you made a mistake. The problem with that was, depending on the setup of your website, it might not work layout wise. Thats why I have replaced it with a nice jQuery alert, similar to the one I am using on <a title="Furasta.Org Website" href="http://Furasta.Org">Furasta</a>. The changes aren&#8217;t large enough to release a new version but I have updated the SVN and supplied a new download link.</p>
<p><a title="Download Mailing List Plugin v0.2" href="http://files.macaoidh.name/webme/mailing-list-0.2.zip">Download</a> | <a href="http://www.monaghanmedicalcentre.com">View Live</a></p>
<h3>News Plugin</h3>
<p>I wrote this plugin trying my best to make it compatible with the Dynamic Search plugin. If you want to create a news page then you just choose news as the page type. To add a new news item you simply create a new subpage of the news page. If you look at the News page in the frontend it will show a summary of all the news items. It is a very simple plugin which has no database, only 4 files and features pagated results. You can also search the News section easily using the Dynamic Search plugin.</p>
<p><a title="Download News Plugin v0.1" href="http://files.macaoidh.name/webme/news-0.1.zip">Download</a> | <a href="http://www.monaghanmedicalcentre.ie/News">View Live</a></p>
<p>I also did quite a lot of work on a Music Store plugin which works similar to the iTunes Store. The plugin is not live yet but it will be soon and in the end I decided not to release it, for the moment anyway, because it gets very complicated when dealing with paypal access details. If anyone wants a copy for it, at a price, I can tailor it for your exact needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/07/29/webme-plugins/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Saving Database Queries</title>
		<link>http://blog.macaoidh.name/2009/05/18/php-saving-database-queries/</link>
		<comments>http://blog.macaoidh.name/2009/05/18/php-saving-database-queries/#comments</comments>
		<pubDate>Mon, 18 May 2009 21:42:38 +0000</pubDate>
		<dc:creator>Conor</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[databade]]></category>
		<category><![CDATA[large project]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[save database queries]]></category>

		<guid isPermaLink="false">http://blog.macaoidh.name/?p=215</guid>
		<description><![CDATA[This is something I wrote today while building botb SNS &#8211; a project that I will have to start blogging about soon! It should be used on large scale projects that have multiple database queries. It will be very useful if you have so many queries that you can&#8217;t keep track of them and are [...]]]></description>
			<content:encoded><![CDATA[<p>This is something I wrote today while building botb SNS &#8211; a project that I will have to start blogging about soon! It should be used on large scale projects that have multiple database queries. It will be very useful if you have so many queries that you can&#8217;t keep track of them and are afraid of re-querying incidentally. Enough said &#8211; down to the code:</p>
<p><code>&lt;?php<br />
class user{<br />
var $id;<br />
var $name='';<br />
var $username='';<br />
var $email='';</code></p>
<p>function __construct($id){<br />
$this-&gt;id=$id;<br />
}<br />
function about($t){<br />
if($this-&gt;$t!=&#8221;) return $this-&gt;$t;<br />
$q=dbRow(&#8216;select &#8216;.$t.&#8217; from users where id=&#8221;&#8216;.$this-&gt;id.&#8217;&#8221;&#8216;);<br />
$this-&gt;$t=$q[$t];<br />
return $this-&gt;$t;<br />
}<br />
}<br />
?&gt;</p>
<p>You will obviously have to adjust this to suit your database setup. It also requires the following function:</p>
<p><code>function dbRow($q){<br />
$s=mysql_query($q);<br />
$r=mysql_fetch_assoc($s);<br />
return $r;<br />
}</code></p>
<p>As you can probably see this example simply echos database information. The main benefit of the class is it will never make the same query twice. Once you ask for the username it is stored within the class so if you ask for it again in the same page it doesn&#8217;t have to query the database again. You could look at it as a type of internal page caching. Also it is incredibly easy to use. All you need to do is:</p>
<p><code>$u=new user($id);<br />
echo 'Query Database: '.$u-&gt;about('name');<br />
echo '&lt;br/&gt; From Memory: '.$u-&gt;about('name');<br />
</code><br />
Easy as that!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.macaoidh.name/2009/05/18/php-saving-database-queries/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
