The basic structure of a java applet

The basic structure of a java applet is illustrated below using the simple "Hello World" example.

Show Plain Text
Java code
  1. // import necessary packages
  2. import java.applet.*;
  3. import java.awt.*;
  4. // Inherit the applet class from the class Applet
  5. public class BasicApplet extends Applet
  6. {
  7.       // init - called the first time you enter the applets HTML page
  8.       public void init() {}
  9.       // start - called every time the applet gets focus
  10.       public void start() {}
  11.       // stop - called if you change focus from the applet
  12.       public void stop() {}
  13.       // destroy - called if you leave the page (e.g. closing browser)
  14.       public void destroy() {}
  15.       // paint - called if you move your browser window or if you
  16.       // call repaint()
  17.       public void paint (Graphics g) {
  18.           g.drawString("Hello World - Wow!?", 0, 0);
  19.       }

To run the applet simply add the following code to your html document, this assumes the compiled class file is located in the same directory as your html document :

Show Plain Text
HTML code
  1. <applet code ="BasicApplet.class" width=200 height=50></applet>

Demo:
Filed under: Java  Tags: Applet

0 Responses to “The basic structure of a java applet”

Sorry, comments have been closed for this post.
(default) 11 queries took 6 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`221
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`221
6DESCRIBE `categories_posts`221
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'the-basic-structure-of-a-java-applet' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (5) 000
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 5 AND `PostsTag`.`tag_id` = `Tag`.`id`) 110
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 5 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 510