<?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; netbeans</title>
	<atom:link href="http://threadbarecanvas.com/tag/netbeans/feed/" rel="self" type="application/rss+xml" />
	<link>http://threadbarecanvas.com</link>
	<description>Online Journal of James Hogan the Web Developer</description>
	<lastBuildDate>Sun, 01 Aug 2010 19:32:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Universal Translator for your Tweets</title>
		<link>http://threadbarecanvas.com/java-web/universal-translator-for-your-tweets/</link>
		<comments>http://threadbarecanvas.com/java-web/universal-translator-for-your-tweets/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 10:21:19 +0000</pubDate>
		<dc:creator>Siriquelle</dc:creator>
				<category><![CDATA[Java Web]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[google translate]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[twitter api]]></category>

		<guid isPermaLink="false">http://threadbarecanvas.com/?p=98</guid>
		<description><![CDATA[I thought this was going to be easy&#8230; SO much for preconceptions. Today, I&#8217;m going to give you the code to create a twitter translation App using, HTML, CSS, JavaScript and Java, the Twitter API and the Google Translate API. In a future tutorial I will demonstrate cross domain Ajax to get this Application to [...]]]></description>
			<content:encoded><![CDATA[<p>I thought this was going to be easy&#8230; SO much for preconceptions. Today, I&#8217;m going to give you the code to create a twitter translation App using, HTML, CSS, JavaScript and Java, the Twitter API and the Google Translate API. In a future tutorial I will demonstrate cross domain Ajax to get this Application to work totally on the client side but in the mean time you will need to have a Java enabled server to execute the server-side <abbr title="Java Server Page">JSP</abbr> that requests the API for twitter.</p>
<p>As you type your tweet the the JavaScript will analyze your keystrokes and check for when a space is entered assuming you are done typing a word, at this point the text is passed to Google for translation. When your done typing hit tweet and it&#8217;s off to twitter with your tweet.</p>
<p>This is what your app will look like when it&#8217;s finished:</p>
<p><a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/translateApp.png"><img class="aligncenter size-full wp-image-99" title="translateApp" src="http://threadbarecanvas.com/wp-content/uploads/2009/07/translateApp.png" alt="translateApp" width="399" height="395" /></a></p>
<p style="text-align: center; font-size: 24px;"><strong><a href="http://threadbarecanvas.com/wp-content/uploads/2009/07/twitterLang.zip" target="_blank">Source</a><br />
</strong></p>
<p>The Folder structure you will need is similar to all other projects. You can download the source folder for this project and open it in NetBeans to get a better idea of how the end result will look. There are no special libraries you need to get this going just java.io.* and java.net.* .</p>
<p>This is the HTML you will need, (/index.html):</p>
<pre class="brush:html">&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" media="screen" href="assets/css/style.css" &gt;
        &lt;title&gt;Twitter Universal Translate&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id="content"&gt;
            &lt;div class="head"&gt;Twitter Multilanguage&lt;/div&gt;

            &lt;form&gt;
                &lt;label class="textlabel" for="username"&gt;Username&lt;/label&gt;
                &lt;input class="textinput" type="text" id="username" name="username" value=""&gt;

                &lt;label class="textlabel" for="password"&gt;Password&lt;/label&gt;
                &lt;input class="textinput" type="password" id="password" name="password" value=""&gt;

                &lt;label class="textlabel" for="lang"&gt;Translate To&lt;/label&gt;
                &lt;select class="select" id="lang" name="lang" onclick="translateTwo()" &gt;
                    &lt;option value="en"&gt;English&lt;/option&gt;
                    &lt;option value="fr"&gt;French&lt;/option&gt;
                    &lt;option value="it"&gt;Italian&lt;/option&gt;
                    &lt;option value="de"&gt;German&lt;/option&gt;
                &lt;/select&gt;

                &lt;label class="textlabel" for="textarea"&gt;Tweet&lt;/label&gt;
                &lt;textarea id="textarea" class="textarea" name="textarea" cols="5" rows="5" onblur="translateTwo()" onkeydown="translate(event)"&gt;&lt;/textarea&gt;

                &lt;input class="textinput" type="button" value="Tweet" onclick="callLoad()"/&gt;
            &lt;/form&gt;
            &lt;div class="infobar"&gt;“Translate your tweet into a chosen language as you type.”&lt;/div&gt;
            &lt;span id="status"&gt;&lt;/span&gt;
        &lt;/div&gt;

        &lt;script type="text/javascript" src="http://www.google.com/jsapi"&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>This is the CSS you will need, (/assets/css/style.css):</p>
<pre class="brush:css">* {
    margin: 0;
    padding: 0;
}

/*///////////////////////////////////////////////////*/

#content{
    color:#333;
    width:350px;
    margin:100px auto;
    border:15px inset #66ffff;
    padding:10px;
    font-family:sans-serif;
    -moz-border-radius:10px;
}

.textlabel,textinput{
    display:block;
}

.textlabel{
    font-weight:bold;
}

.textlabel,.textinput, .textarea,.select{
    width:200px;
}

.textinput, .textarea,.select{
    padding:1px;
    margin-bottom:5px;
}

.textinput:focus, .textarea:focus{
    background-color:#ffffcc;
}

.head{
    font-size:32px;
    font-family:sans-serif;
    font-weight:bold;
    margin-bottom:5px;
}

.infobar{
    width:120px;
    float:right;
    position:relative;
    top:-140px;
    left:0px;
    padding: 3px;
    border:5px #ffff99 solid;
    background-color:#ffffcc;
    color:#003333;
    font-size:14px;
    font-style:oblique;
    text-align:center;
}</pre>
<p>This is the JavaScript you will need, (/assets/js/jscript.js):</p>
<pre class="brush:jscript">google.load("language", "1");

function translate(event){
    var textarea = document.getElementById("textarea");
    var lang = document.getElementById("lang");

    if(event.keyCode == 32){
        google.language.translate(textarea.value, "", lang.value, function(result) {
            if (!result.error) {
                var container = document.getElementById("textarea");
                container.value = result.translation + " ";
            }
        });
    }
}

function translateTwo(){
    var textarea = document.getElementById("textarea");
    var lang = document.getElementById("lang");
    google.language.translate(textarea.value, "", lang.value, function(result) {
        if (!result.error) {
            var container = document.getElementById("textarea");
            container.value = result.translation + " ";
        }
    });
}

function load(url, callback) {
    var xhr = new XMLHttpRequest();

    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var status = document.getElementById("textarea").value;
    var auth = "tweet.jsp?username="+username+"&amp;password="+password+"&amp;status="+status;

    xhr.onreadystatechange = function() {
        if((xhr.readyState &lt; 4) || xhr.status !== 200) return;
        callback(xhr);
    };
    try{
        xhr.open('GET', auth, true);
        xhr.send();
    }catch(e){
        document.write(e);
    }
}

function callLoad(){
    load('tweet.jsp', function(xhr) {
        var joke = document.getElementById("status");
        var textarea = document.getElementById("textarea");
        joke.innerHTML = '<strong>OK</strong>';
        textarea.value = '';
    });
}</pre>
<p>This is the Java you will need, (/tweet.jsp):</p>
<pre class="brush:java">&lt;%@page import="java.net.*, java.io.*"%&gt;
&lt;%
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String status = request.getParameter("status");
        try {
            String twitteruser = username;
            String twitterpass = password;
            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) {
                out.println(decodedString);
            }
            in.close();

        } catch (Exception e) {
            System.out.println(e.toString());
        }

%&gt;</pre>
<p>Ideally a Servlet would be best suited to processing the response from twitter but for this project it&#8217;s OK. And there you go you can now tweet in multiple languages like James Bond might. yay!</p>
<p><map name='google_ad_map_98_d0b0fa17a4b5b092'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/98?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_98_d0b0fa17a4b5b092' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=98&amp;url= http%3A%2F%2Fthreadbarecanvas.com%2Fjava-web%2Funiversal-translator-for-your-tweets%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://threadbarecanvas.com/java-web/universal-translator-for-your-tweets/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>
