RSS feed
<< October 25, 2007 | Home | October 27, 2007 >>

Java programming

In the Adobe Flash Player post I talked about how Flash can add functionality to the web browser. Java, while less ubiquitous as a browser add-on, is another piece of software that can add functionality to your web browser. Adobe had a census conducted in September 2007 and came up with the graph below which shows the relative market penetration of these two add-ons. These numbers are important because they tell an author using one of these technologies, how likely it will be that someone visiting their page will be able to run their program. The add-on for the browsers that PLAYS the objects are generally distributed for free; Adobe assumes they'll make the money on the software that EDITS the objects. Adobe charges $699 for their Flash editor. You can download a variety of Java editors that are available for free.

In this post I'd like to show you how easy it is to create a Java applet that you can include in your website or blog. We will be using free software and the process should be easy enough for anyone to follow. We're going to be creating the applet featured in the Internet file sharing post that displays the words "Hello world". First you'll need to make sure you have the latest Java version of the installed. If you don't have Java installed, you can find it at the Java website.

  1. Visit the eclipse site and download "Eclipse IDE for Java Developers".
  2. Unzip the contents of the zip file.
  3. Run eclipse.exe (it will ask you to specify the location for a workspace, press ok).
  4. Select the Workbench icon (you can return to this screen by selecting "welcome" from the Help menu).
  5. From the File menu select "New" then "Java Project". Specify "helloworld" as the "Project name" then click "Finish".
  6. From the File menu select "New" then "Class". Specify "HelloWorld" as the "name" then click "Finish".
  7. Paste the following code. To correct the indentation, select all by pressing Ctrl+A then Ctrl+I.
  8. import java.applet.*;
    import java.awt.*;
    
    public class HelloWorld extends Applet {
    	static final long serialVersionUID = 1L;
    	public void paint(Graphics g) {
    		g.drawString("Hello world", 10 , 10);
    	}
    }
    
  9. Select Save from the File menu or press Ctrl+S.
  10. Select "Run" from the "Run" menu or press Ctrl+F11. You should see the Applet Viewer appear on your screen with your applet running inside displaying the test "Hello World".
  11. You will find the HelloWorld.class file by selecting "Window", "Show View", "Navigator". The class file is under the bin folder. You can publish the applet to your blog by uploading the class file to a file hosting service and adding the following tag to your own blog post. You will need to modify the code and the codebase attributes. Read my post on Internet file sharing for more information.
  12. <applet alt="Browser has Java disabled" 
    width="425" height="350" code="HelloWorld.class">
    </applet>
    
Tags :
<< October 25, 2007 | Home | October 27, 2007 >>