<?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>Threadbare Canvas Productions &#187; tutorial</title>
	<atom:link href="http://threadbarecanvas.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://threadbarecanvas.com</link>
	<description>Online Journal of James Hogan the Web Developer</description>
	<lastBuildDate>Fri, 06 Jan 2012 09:59:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>One Way Tweet a Java App</title>
		<link>http://threadbarecanvas.com/java/one-way-tweet-a-java-app/</link>
		<comments>http://threadbarecanvas.com/java/one-way-tweet-a-java-app/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:33:31 +0000</pubDate>
		<dc:creator>Siriquelle</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter api]]></category>

		<guid isPermaLink="false">http://threadbarecanvas.com/?p=115</guid>
		<description><![CDATA[One way tweet is a sending application for twitter. In this tutorial you will see/learn how to send stuff to twitter by writing a java desktop UI. You will create a new project in NetBeans and choose java application, and create a new package called org.me.owt. Then, create a new java source file and call it [...]]]></description>
			<content:encoded><![CDATA[<p>One way tweet is a sending application for twitter. In this tutorial you will see/learn how to send stuff to twitter by writing a java desktop UI. You will create a new project in NetBeans and choose java application, and create a new package called org.me.owt. </p>
<p>Then, create a new java source file and call it main.java, and another called tweet.java. Two simple classes and you&#8217;ve got yourself a twitter client. The end result will look like this:<br />
<a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/owt.png"><img src="http://threadbarecanvas.com/wp-content/uploads/2009/07/owt.png" alt="One Way Tweet" title="One Way Tweet" width="309" height="312" class="aligncenter size-full wp-image-116" /></a></p>
<pre class="brush:java">
/*
 * Main.java
 *
 * Created on 23-Jul-2009, 11:57:04
 */
package org.me.owt;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Siriquelle
 */
public class Main extends javax.swing.JFrame {

    private JButton button;

    /** Creates new form Main*/
    public Main() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        usernamelabel = new java.awt.Label();
        username = new java.awt.TextField();
        passwordlabel = new java.awt.Label();
        password = new java.awt.TextField();
        status = new java.awt.TextArea();
        tweet = new java.awt.Button();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("One Way Tweet");
        setBackground(new java.awt.Color(204, 255, 255));
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setForeground(new java.awt.Color(204, 255, 255));
        setName("One Way Tweet"); // NOI18N
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(204, 255, 255));
        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setAlignmentX(getWidth() / 2);
        jPanel1.setAlignmentY(getHeight() / 2);

        usernamelabel.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        usernamelabel.setForeground(new java.awt.Color(0, 102, 102));
        usernamelabel.setName("usernameLabel"); // NOI18N
        usernamelabel.setText("Username");

        username.setForeground(new java.awt.Color(51, 51, 51));
        username.setName("username"); // NOI18N
        username.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusGained(java.awt.event.FocusEvent evt) {
                Main.this.focusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                Main.this.focusLost(evt);
            }
        });

        passwordlabel.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        passwordlabel.setForeground(new java.awt.Color(0, 102, 102));
        passwordlabel.setName("passwordLabel"); // NOI18N
        passwordlabel.setText("Password");

        password.setEchoChar('*');
        password.setForeground(new java.awt.Color(51, 51, 51));
        password.setName("password"); // NOI18N
        password.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusGained(java.awt.event.FocusEvent evt) {
                Main.this.focusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                Main.this.focusLost(evt);
            }
        });

        status.setForeground(new java.awt.Color(51, 51, 51));
        status.setName("status"); // NOI18N
        status.addFocusListener(new java.awt.event.FocusAdapter() {

            @Override
            public void focusGained(java.awt.event.FocusEvent evt) {
                Main.this.focusGained(evt);
            }

            @Override
            public void focusLost(java.awt.event.FocusEvent evt) {
                Main.this.focusLost(evt);
            }
        });

        tweet.setActionCommand("tweet");
        tweet.setBackground(new java.awt.Color(153, 255, 255));
        tweet.setFont(new java.awt.Font("Impact", 1, 48)); // NOI18N
        tweet.setForeground(new java.awt.Color(0, 102, 102));
        tweet.setLabel("tweet");
        tweet.setName("tweet"); // NOI18N
        tweet.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tweetMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE).addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(passwordlabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(usernamelabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))).addComponent(tweet, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap()));
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(usernamelabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(passwordlabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(tweet, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()));

        usernamelabel.getAccessibleContext().setAccessibleName("usernameLabel");
        username.getAccessibleContext().setAccessibleName("username");
        password.getAccessibleContext().setAccessibleName("password");
        status.getAccessibleContext().setAccessibleName("status");
        tweet.getAccessibleContext().setAccessibleName("tweet");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE));

        getAccessibleContext().setAccessibleName("One Way Tweet");
        getAccessibleContext().setAccessibleDescription("One Way Tweet");

        pack();
    }// </editor-fold>

    private void tweetMouseClicked(java.awt.event.MouseEvent evt) {
        Tweet tw = new Tweet(username.getText(), password.getText(), status.getText());
        if (tw.sendTweet())
        {
            this.ShowMessageDialog("Tweet Win");
        } else
        {
            this.ShowMessageDialog("Tweet Fail");
        }
    }

    private void focusGained(java.awt.event.FocusEvent evt) {
        evt.getComponent().setBackground(new java.awt.Color(255, 255, 215));
    }

    private void focusLost(java.awt.event.FocusEvent evt) {
        evt.getComponent().setBackground(new java.awt.Color(255, 255, 255));
    }

    public void ShowMessageDialog(String msg) {
        final JFrame frame = new JFrame(msg);
        button = new JButton("OK");
        button.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                frame.dispose();
            }
        });

        JPanel panel = new JPanel();
        panel.add(button);
        panel.add(button);
        frame.add(panel);
        frame.setSize(220, 80);
        frame.setLocation(220, 80);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JPanel jPanel1;
    private java.awt.TextField password;
    private java.awt.Label passwordlabel;
    private java.awt.TextArea status;
    private java.awt.Button tweet;
    private java.awt.TextField username;
    private java.awt.Label usernamelabel;
    // End of variables declaration
}
</pre>
<p>The following code is a class that handles the tweet. create a new java source file in the org.me.owt package and call it tweet.java. It&#8217;s methods are used to create and send the tweet and handle the response from the twitter api:</p>
<pre class="brush:java">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.me.owt;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

/**
 *
 * @author Siriquelle
 */
public class Tweet {

    private String twitteruser;
    private String twitterpass;
    private String status;
    private String response;

    public Tweet(String u, String p, String s) {
        twitteruser = u;
        twitterpass = p;
        status = s;
    }

    public boolean sendTweet() {
        try
        {
            String encodedData = URLEncoder.encode(status, "UTF-8");

            String credentials = twitteruser + ":" + twitterpass;
            String encodecredentials = new sun.misc.BASE64Encoder().encode(credentials.getBytes());

            URLConnection connection = null;
            URL url = new URL("http://twitter.com/statuses/update.xml");
            connection = url.openConnection();
            connection.setRequestProperty("Authorization", "Basic " + encodecredentials);
            connection.setDoOutput(true);

            OutputStreamWriter output = new OutputStreamWriter(connection.getOutputStream());
            output.write("status=" + encodedData);
            output.close();

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String decodedString;
            while ((decodedString = in.readLine()) != null)
            {
                response = decodedString;
            }
            in.close();
            return true;
        } catch (Exception e)
        {
            response = e.toString();
            return false;
        }
    }
}
</pre>
<p>And thats the code, right click your project and choose run. After you examine this code you&#8217;ll discover how, with a little parsing you can turn this application into a fully fledged thwirl competitor. :) If you&#8217;ve any questions I&#8217;d love a go at answering.</p>
<p>This application was created in netbeans using the swing UI builder. In a future post I will describe the process to building an application using the NetBeans IDE and it&#8217;s UI builders in design view.</p>
<p><map name='google_ad_map_115_d0b0fa17a4b5b092'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/115?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_115_d0b0fa17a4b5b092' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=115&amp;url= http%3A%2F%2Fthreadbarecanvas.com%2Fjava%2Fone-way-tweet-a-java-app%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://threadbarecanvas.com/java/one-way-tweet-a-java-app/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Creating a JavaWeb Email Contact Form</title>
		<link>http://threadbarecanvas.com/java-web/creating-a-javaweb-email-contact-form/</link>
		<comments>http://threadbarecanvas.com/java-web/creating-a-javaweb-email-contact-form/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 22:29:06 +0000</pubDate>
		<dc:creator>Siriquelle</dc:creator>
				<category><![CDATA[Java Web]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javaMail]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://threadbarecanvas.com/?p=82</guid>
		<description><![CDATA[In a previous tutorial I have explained how to create a new NetBeans project and add a library to it to make the classes that are available in a jar available to use in your own project. If you are unsure how to do this go ahead and check out this article. In this tutorial [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous tutorial I have explained how to create a new NetBeans project and add a library to it to make the classes that are available in a <abbr title="Java Archive file">jar</abbr> available to use in your own project. If you are unsure how to do this go ahead and check out <a href="http://threadbarecanvas.com/java/creating-a-pdf-programmatically-with-itext/">this article</a>.</p>
<p style="text-align: left;">In this tutorial I&#8217;m going to explain how to create a contact form with a jQuery validation template for you to play with that will send an email to whomever. The end result should look like this:</p>
<p style="text-align: center;"><a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/form.png"><img class="size-full wp-image-85 aligncenter" title="form" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/form.png" alt="form" width="503" height="397" /></a></p>
<p style="text-align: center; font-size: 24px;"><strong><a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/Contactform.zip" target="_blank">Source</a><br />
</strong></p>
<p>Your going to need some form of access to an smtp mailbox with a username and password. You can use your gmail account info if you like, all your going to need is your gmail address and password.<br />
<a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/gmail.png"><img class="alignnone size-full wp-image-86" title="gmail" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/gmail.png" alt="gmail" width="551" height="167" /></a></p>
<p>Now for the fun part, First of all you need to set up a new web application project in netBeans I&#8217;ve called mine ContactForm. In the index.jsp file in the root of your directory you should past this html structure. It&#8217;s going to set up the form. Simple elegant yet expandable if you want. You&#8217;ll see how easy it is to build custom emails with this form by adding new fields and manipulating a variable or two near the end of this tutorial.</p>
<pre class="brush:html">&lt;%@page import="mail.SendEmail" %&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" &gt;
        &lt;link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/reset/reset-min.css"&gt;
        &lt;link href="assets/css/style.css" rel="stylesheet" type="text/css" media="screen" &gt;
        &lt;title&gt;Multilingual Contact Form&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id="container"&gt;
            &lt;p class="heading"&gt;Contact Form&lt;/p&gt;
            &lt;form action="index.jsp" method="POST"&gt;
                &lt;div class="input"&gt;
                    &lt;label for="fullname"&gt;Name:&lt;/label&gt;
                    &lt;input type="text" id="fullname" name="fullname" value="" /&gt;
                    &lt;div id="fullname_warn" &gt;&lt;/div&gt;
                &lt;/div&gt;

                &lt;div class="input"&gt;
                    &lt;label for="email" &gt;Email:&lt;/label&gt;
                    &lt;input type="text" id="email" name="email" value="" /&gt;
                    &lt;span id="email_warn" &gt;&lt;/span&gt;
                &lt;/div&gt;

                &lt;div class="input"&gt;
                    &lt;label for="message" &gt;Message:&lt;/label&gt;
                    &lt;textarea cols="10" rows="5" id="message" name="message"&gt;&lt;/textarea&gt;
                &lt;/div&gt;

                &lt;input type="submit" name="send" value="send" id="send" /&gt;
            &lt;/form&gt;

            &lt;%
        if (request.getParameter("fullname") != null) {
            String fullname = request.getParameter("fullname");
            String email = request.getParameter("email");
            String message = request.getParameter("message");

            if (mail.SendEmail.run(email, fullname, message)) {
            %&gt;
            &lt;p class="goodtogo end"&gt;Mail Sent Successfully&lt;/p&gt;
            &lt;%} else {%&gt;
            &lt;p class="warning end"&gt;Error Sending Mail&lt;/p&gt;
            &lt;%}
        }
            %&gt;

        &lt;/div&gt;
        &lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" src="assets/js/jscript.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>Now that the html structure is in place it&#8217;s time to transform it into something a little easier on the eye. We&#8217;re going to add some styles. Before you go ahead and do this you should go ahead and set up your folder structures. It&#8217;s imperative that you have your files arranged in an organized way so that other developers can easily find what their looking. That, and if you need to take pictures to remember a holiday then you should defiantly be making your documents easier to find. Your folder structure should look like this:<br />
<a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/folderstructure.png"><img class="alignnone size-full wp-image-87" title="folderstructure" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/folderstructure.png" alt="folderstructure" width="214" height="487" /></a></p>
<p>Now that youve got somewhere to put your styles you should go ahead and stick them in this folder. Here they are:</p>
<pre class="brush:css">div#container{
    max-width:578px;
    min-width:440px;
    border:1px solid #222;
    padding:20px;
    margin:100px auto;
    color:#222233;
    font-family:sans-serif;
    -moz-border-radius:20px;
}

p.heading{
    font-size:36px;
    font-weight:bold;
}

.input,#send{
    font-size:24px;
    margin-top:10px;
}

.input label{
    display:block;
    text-decoration:underline;
}

.input input, .input textarea{
    width:300px;
    padding:1px;
}

#send{
    font-size:16px;
    cursor:pointer;
    width:120px;
    height:50px;
}

.warning, .goodtogo{
    font-size:20px;
    padding-left:35px;
    width:225px;
    height:33px;
    float:right;
    clear:right;

}

.warning{
    background:transparent url(../img/warn.png) no-repeat -5px -33px scroll;
}

.goodtogo{
    background:transparent url(../img/warn.png) no-repeat 0px 0px scroll;
}

.end{
    position:relative;
    top:-40px;
}</pre>
<p>Now you need a sprite for your error icons. I&#8217;ve made this one you should stick it in the &#8216;img&#8217; folder your created under &#8216;assets&#8217; like the structure shown above.<br />
<a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/warn.png"><img class="alignnone size-full wp-image-84" title="warn" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/warn.png" alt="warn" width="40" height="60" /></a></p>
<p>The following demonstrates dynamic class application with JQuery. You should play around with this fill and add validation to the form fields while getting familiar with the JQuery framework:</p>
<pre class="brush:jscript">$(document).ready(function() {

    var fullname = $('#fullname');
    var fullname_warn = $('#fullname_warn');

    var email = $('#email');
    var email_warn = $('#email_warn');

    fullname.focus(function(){
        fullname_warn.removeClass('goodtogo');
        fullname_warn.addClass('warning');
        fullname_warn.html("Cannot be blank");

        fullname.blur(function(){
            fullname_warn.removeClass('warning');
            fullname_warn.addClass('goodtogo');
            fullname_warn.html(" ");
        });
    });

    email.focus(function(){
        email_warn.removeClass('goodtogo');
        email_warn.addClass('warning');
        email_warn.html("Cannot be blank");

        email.blur(function(){
            email_warn.removeClass('warning');
            email_warn.addClass('goodtogo');
            email_warn.html(" ");
        });
    });

});</pre>
<p>Now that we have a base structure in place it&#8217;s time to start bringing in the JavaMail API into your project. Ive made it available to <a href="http://files.getdropbox.com/u/414996/mail.jar">download here</a> so you can just download it. Ok? Create a JavaMail library and add it to your project as in the<a href="http://threadbarecanvas.com/java/creating-a-pdf-programmatically-with-itext/"> iText tutorial.</a></p>
<p>So the final step in this is easy&#8230; Create a new package called &#8216;mail&#8217; in your Source Packages roll out in your project folder structure as seen here:<br />
<a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/javaClassStructure.png"><img class="alignnone size-full wp-image-88" title="javaClassStructure" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/javaClassStructure.png" alt="javaClassStructure" width="214" height="55" /></a></p>
<p>As you can see from above a new Java Class file called SendMail has been added to the &#8216;mail&#8217; package, create that file now and add this code to it:</p>
<pre class="brush:java">package mail;

/**
 *
 * @author Siriquelle
 */
import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author Siriquelle
 */
public class SendEmail {

    public static boolean run(String addressedTo, String subject, String content) {

        String fromAddress = "Your Name ";//Your Email Address//
        String recipients = addressedTo.trim();
        String contentType = "text/plain";

        String smtpHost = "smtp.gmail.com";//Your Outgoing Mailbox//
        int smtpPort = 587;
        String username = "you@gmail.com";//Your Mailbox Username//
        String password = "yourpassword";//Your Mailbox Password//

        try
        {
            Properties props = System.getProperties();
            props.put("mail.smtp.starttls.enable", "true");
            Session session = Session.getDefaultInstance(props);

            MimeMessage message = new MimeMessage(session);

            message.setFrom(new InternetAddress(fromAddress));
            message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse(recipients, false));

            message.setSubject(subject);
            message.setContent(content, contentType);
            message.setSentDate(new Date());

            Transport transport = session.getTransport("smtp");
            transport.connect(smtpHost, smtpPort, username, password);
            transport.sendMessage(message, message.getAllRecipients());
            transport.close();

            return true;
        } catch (MessagingException messagingException)
        {
            System.out.print(messagingException);
            return false;

        } catch (Exception e)
        {
            System.out.print(e);
            return false;
        }
    }
}</pre>
<p>And that is it. You should now have a valid working form that will send emails. Nice. If you don&#8217;t check that your folder structure matches <a title="Folder Structure" href="http://threadbarecanvas.com/wp-content/uploads/2009/07/folderstructure.png" target="_blank">mine</a>. Check that you&#8217;ve added your own GMail username and password in the SendEmail java class.</p>
<p><map name='google_ad_map_82_d0b0fa17a4b5b092'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/82?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_82_d0b0fa17a4b5b092' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=82&amp;url= http%3A%2F%2Fthreadbarecanvas.com%2Fjava-web%2Fcreating-a-javaweb-email-contact-form%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://threadbarecanvas.com/java-web/creating-a-javaweb-email-contact-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handcrafting a MySQL Database</title>
		<link>http://threadbarecanvas.com/mysql/handcrafting-a-mysql-database/</link>
		<comments>http://threadbarecanvas.com/mysql/handcrafting-a-mysql-database/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 12:30:21 +0000</pubDate>
		<dc:creator>Siriquelle</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://threadbarecanvas.com/?p=26</guid>
		<description><![CDATA[The natural progression for a developer of web applications is for them to eventually be able to create a solid persistent web application. Solid in that is is robust to scalability and persistent in that the data you create while using it gets stored on the cloud, as it were. Cloud computing is a new [...]]]></description>
			<content:encoded><![CDATA[<p>The natural progression for a developer of web applications is for them to eventually be able to create a solid persistent web application. Solid in that is is robust to scalability and persistent in that the data you create while using it gets stored on the cloud, as it were. Cloud computing is a new way of imagining how data will be handled online. Instead of your data residing on a single hard-drive on your home computer or on a web server somewhere your data will be shifting through the cloud as resources are negotiated automatically to handle the breath of demand for your content.</p>
<p>In this example I&#8217;m going to show you how to download, install, create and query a MySQL database. In a future post I&#8217;ll show how to connect a JSP page to a database and display some content onto a page. This will be the first steps to creating a Content Management System of sorts, but I&#8217;ll leave that for now.</p>
<p>So, First step should be to download MySQL server. if you&#8217;ve got a Microsoft computer then choose the download that corresponds to <a title="MySQL Download" href="http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.36-win32.msi/from/pick#mirrors" target="_blank">your country</a>. After you&#8217;ve downloaded and installed everyting agreeing to everything along the way, you should get to the MySQL Server Instance Configuration Wizard:</p>
<p><img class="alignnone size-full wp-image-30" title="1" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/1.png" alt="1" width="511" height="389" /></p>
<p>It&#8217;s OK to keep hitting Next here until your asked for a password and choose &#8216;admin&#8217;.</p>
<p>Great, now you have it all installed and you are on your way to having a database up and running on your computer. What you need to do now is turn to your start menu and locate the MySQL command line client. This will allow you to start handcrafting a database:</p>
<p><img class="alignnone size-full wp-image-31" title="MySQL Command Line Client" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/2.png" alt="MySQL Command Line Client" width="667" height="333" /></p>
<p>Add the following line and press return</p>
<pre class="brush:sql">CREATE DATABASE helloworld;</pre>
<p>Well, it does exactly what it says. It creates a database referenced with the name helloworld. Go ahead and execute this line now. MySQL will respond to you if all is well saying:</p>
<pre>Query OK, 1 row affected (0.02 sec)</pre>
<p>Now that we have our database we can start to have some fun. Next you need to tell MySQL that you want to use the database we&#8217;ve just created. So you can execute this command:</p>
<pre class="brush:sql">USE helloworld;</pre>
<p>A this point you should have created a database and told MySQL that you want to use it. So now lets add a table to the database helloworld. Add and execute the following lines to create a table on helloworld name helloworld:</p>
<pre class="brush:sql">CREATE TABLE helloworld(
HELLO char(10) NOT NULL,
WORLD char(10) NOT NULL
)ENGINE InnoDB;</pre>
<p>If all is ok MySQL should respond to you with the following screen:</p>
<p><img class="alignnone size-full wp-image-32" title="Creating a Table" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/3.png" alt="Creating a Table" width="666" height="332" /></p>
<p>Now that we&#8217;ve got our table created we can go ahead and stick some data in there like so:</p>
<pre class="brush:sql">INSERT INTO helloworld(HELLO, WORLD)
VALUES("Hello","World");</pre>
<p>The previous two lines allow us to populate or table with the data &#8220;Hello&#8221; and &#8220;World&#8221;. The fun part comes when we attempt to see the fruits of our labor. Using the following line we can see the data we&#8217;ve just created returned by MySQL.</p>
<pre class="brush:sql">SELECT HELLO, WORLD
FROM helloworld;</pre>
<p><img class="alignnone size-full wp-image-33" title="4" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/4.png" alt="4" width="666" height="332" /><br />
Be Amazed you are now a budding database Developer. In a future post I will explain how we can connect to this database and retrieve our Hello and World and stick them into a JSP page. :)</p>
<p><map name='google_ad_map_26_d0b0fa17a4b5b092'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/26?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_26_d0b0fa17a4b5b092' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=26&amp;url= http%3A%2F%2Fthreadbarecanvas.com%2Fmysql%2Fhandcrafting-a-mysql-database%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://threadbarecanvas.com/mysql/handcrafting-a-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Web &#8216;Hello World&#8217;</title>
		<link>http://threadbarecanvas.com/java-web/java-web-hello-world/</link>
		<comments>http://threadbarecanvas.com/java-web/java-web-hello-world/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 12:43:33 +0000</pubDate>
		<dc:creator>Siriquelle</dc:creator>
				<category><![CDATA[Java Web]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://threadbarecanvas.com/?p=1</guid>
		<description><![CDATA[As a Web Developer I naturally enjoy web development and writing a blog has always been on my mind. I start and stop and start and well. You get the message. I’ve even tried my hand at podcasting. With this post I want to introduce people to the NetBeans IDE and to get us started [...]]]></description>
			<content:encoded><![CDATA[<p>As a Web Developer I naturally enjoy web development and writing a blog has always been on my mind. I start and stop and start and well. You get the message. I’ve even tried my hand at podcasting. With this post I want to introduce people to the NetBeans IDE and to get us started I want to show how to get a hello world running in java through a JSP page. In the future I&#8217;ll talk about Servlets and session handling but for now it&#8217;s get up and running time.</p>
<p>I love java for some reason. Maybe because it&#8217;s the first language I really sunk my teeth into.  Anyhow, first off any aspiring developer should download install and familiarize themselves with an IDE. IDE stands for Integrated Development Environment. Some people swear by Eclipse because of its extensibility and it has its uses but for me NetBeans has it made. It&#8217;s released by Sun, the JAVA people so it&#8217;s got some neat features like auto formatting that make a developers life easier.</p>
<p>So, first you need to travel to <a title="netBeans" href="http://www.netbeans.org/downloads/index.html" target="_blank">NetBeans.org</a> and download the latest version of NetBeans. You should be looking for the Java version or the all version. Really you just want a version that ticks the Java Web and EE box. Oh, and make sure you&#8217;ve got JavaScript enabled or you won&#8217;t see anything.</p>
<p><img class="alignnone size-full wp-image-5" title="netBeans Download" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/netbeansDownload.png" alt="netBeans Download" width="535" height="226" /></p>
<p>After NetBeans is downloaded you can go ahead and run it. Agree to everything as it loads. And after it loads simply go to file &gt; new project and you should see something looking like this:</p>
<p><img class="alignnone size-full wp-image-6" title="netBeans Hello World" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/demoWeb.png" alt="netBeans Hello World" width="515" height="254" /></p>
<p>Choose Java Web &gt; Web Application and click next. After you&#8217;ve done this you should see the next window in the &#8216;New Java Web Application Wizard. All you need o concern yourself with is the box i have highlighted, i.e. Give your new web application a name, I chose HelloWorld but you can choose any name you wish. It&#8217;s best if you don&#8217;t use spaces in the name just yet however.</p>
<p><img class="alignnone size-full wp-image-7" title="Java Web Application Wizard" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/demoWeb1.png" alt="Java Web Application Wizard" width="515" height="260" /></p>
<p>After you&#8217;ve chosen a name for your &#8216;Hello World&#8217; application you should select Next and then select Finish on the final page. In another post I will explain what each of the options mean specifically but for now we’re going to focus on the &#8216;Hello World&#8217;. There’s nothing like the first app feeling. As developers we are constantly learning new technologies and from time to time that feeling returns but the first is unique.</p>
<p>At this point you should see something like HTML code in the center of your screen. This is your editor window and here is where you will edit and manage all of your code.</p>
<p>To the left you should be seeing your project tree. It shows you index.jsp by default:</p>
<p><img class="alignnone size-full wp-image-8" title="Project and Files" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/projectFiles.png" alt="Project and Files" width="538" height="374" /></p>
<p>To execute your project you need to right click on your project and choose run from the drop down list. You will notice allot of things start to happen. JSP pages are compiled and rendered by a web server and displayed in your browser. So far this index.jsp page does nothing special and if its contents were contained in a .html page instead the browser would render it just the same.</p>
<p>Now, try adding this code to the top of your JSP page:</p>
<pre class="brush:[java]">&lt;%
String h = "hello";
String w = "world";
%&gt;</pre>
<p>And add this code to the between the body tags of your JSP page:</p>
<pre class="brush:[java]">&lt;h1&gt;
&lt;%= h + w + "!!" %&gt;
&lt;/h1&gt;</pre>
<p>Your page should look something like this after you’re done:</p>
<p><img class="alignnone size-full wp-image-9" title="JSP Hello World Example" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/projectFiles1.png" alt="JSP Hello World Example" width="482" height="354" /></p>
<p>Save the page in NetBeans and refresh the page in your browser and you get the same result, but this time you&#8217;ve been programming in java. Congratulations your Java Web story has begun. In the next post in the series I will explain what a String is and how it works. :)</p>
<p><map name='google_ad_map_1_d0b0fa17a4b5b092'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_1_d0b0fa17a4b5b092' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=1&amp;url= http%3A%2F%2Fthreadbarecanvas.com%2Fjava-web%2Fjava-web-hello-world%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://threadbarecanvas.com/java-web/java-web-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

