logo
g Text Version
Auto
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Society & Culture
Sports
Travel & Leisure
TV & Movies

dailyclick
Bored? Games!
Postcards
Astrology
Take a Quiz
Rate My Photo

new
Ethnic Beauty
Adolescence
Middle Eastern Culture
Yoga
Vision Issues
Paper Crafts
Comedy Movies


dailyclick
All times in EST

Autism Spectrum Disorders: 4:00 PM

Full Schedule
g
g JavaScript / Java Site
Editor Wanted
BellaOnline's JavaScript / Java Editor

g

Java Applets and Applications
Guest Author - Julie L Baumler

Java programs can take two forms, they can be a standalone application or they can be an applet – a (usually) small program that runs within a web browser. When Java first came out, applets were probably the most popular type of Java program because they were the best, if not only way, to add interactivity, animation, and useful functionality to web pages. Now there are many good ways to provide these things and programmers (and managers!) have become more aware of the benefits of Java as a general purpose programming language and applications get all the press. No matter what your interest in Java, it is useful to understand a little bit about both types of Java programs.

Below is an example of a simple (and pretty much useless) application, apply named SimpleApplication, that prints a single line of text. A hallmark of applications is that they always have a main method.

class SimpleApplication {
public static void main(String[] args) {
// Print the line of text
System.out.println("I am a very boring application.");
}
}

This results in the following application:
I am a very boring application.

Below is an example of a very simple applet, unsurprisingly named SimpleApplet. It too prints a single line of text, this time to the applet pane in a web browser. Applets do not have a main method and they need to import either the java.applet.Applet or the javax.swing.JApplet class. (The later is needed if you use swing components.)

import java.applet.Applet;
import java.awt.Graphics;

public class SimpleApplet extends Applet {
public void init() {
resize(150,25);
}
public void paint(Graphics g) {
g.drawString("I am a very boring applet", 50, 25);
}
}

The applet is then included in a web page using the object tag, for this applet. For instance:

<applet code="SimpleApplet.class" width="150" height="40">
Simple Java Applet
</applet>

You may also see the applet tag, however, be aware that it is depreciated. The equivalent applet tag would be:

<object codetype="application/java"
classid="java:SimpleApplet.class"
width="150" height="40" >
Simple Java Applet
</object>

You can see this applet in action and download the source code for both the applet and the application here.
Need ready to use applets for your web pages? Instant Java is your answer. Order from Amazon.com or Alibris.

This site needs an editor - click to learn more!

Beginners Resources
Java for Programmers
Web Page Add-Ons
RSS
Related Articles
Previous Features
Site Map

Add Java+Applets+and+Applications to Twitter Add Java+Applets+and+Applications to Facebook Add Java+Applets+and+Applications to MySpace Add Java+Applets+and+Applications to Del.icio.us Digg Java+Applets+and+Applications Add Java+Applets+and+Applications to Yahoo My Web Add Java+Applets+and+Applications to Google Bookmarks Add Java+Applets+and+Applications to Stumbleupon Add Java+Applets+and+Applications to Reddit


Content copyright © 2009 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


For FREE email updates, subscribe to the JavaScript / Java Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor

g features
Hearing Dog Tool - Adding Randomness

Hearing Dog Training Tool – setTimeout()

GCJ - an Independant Java Implementation

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter

jobs
what
job title, keywords
where
city, state or zip
jobs by job search


vote
Growing a Garden
Veggies and Flowers
Veggies Only
Flowers Only
No Garden

g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2009 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor