LINKS

Java Tutor Homepage

Java Applications and Components

Java Applets and Components

Java Frequently Asked Questions:
    1. What is Inheritance?
    2. What is Polymorphism?
    3. What is Encapsulation?
    4. Avoiding the Divide by Zero Error
    5. Public Classes in Java Source Files
    6. The Import Statement in Java
    7. Classes with Default Access
    8. What are Local Variables?
    9. What is an Abstract Method?
    10. Data Structures
    11. What is Autoboxing and Auto-Unboxing?
    12. What is multithreading?
    13. What are Threads?
    14. Thread States
    15. What is the Purpose of Synchronization?
    16. Thread Interaction
    17. Can You Start a Thread Twice?

Features of Java Applets and Components

In order to better understand how a Java Applet works, let’s look at an example:
The Christmas Tree Applet displays a Christmas tree in the background, shows snow falling to the ground, and has a banner which says “Merry Christmas” scrolling across the bottom of the applet. When the applet container loads the ChristmasTree class, the container creates an object of type ChristmasTree, then calls the init method, the start method, and the paint method in that order. The ChristmasTree class has a number of instance variables that hold information about the locations of all the snow flakes, the location of the “Merry Christmas” banner, and both the “Merry Christmas” banner image and the Christmas tree image. The init method loads the “Merry Christmas” banner image and Christmas tree image from the directory the applet is located to the image objects declared for storing them in. The init method then uses the ran_num object to generate x and y coordinates for all of the snow flakes. The start method simply declares and starts the animation thread. The run method runs the animation thread every 200 milliseconds. The paint methods repaints the screen; it does this by drawing the Christmas tree to the window, then updating the locations of all of the snow flakes, then draws all of the snow flakes, and then draws the “Merry Christmas” banner. The paint method also contains code to ensure that when a snow flake gets to near the bottom of the applet window, it is sent back to the top of the apply window, as well as code that ensures that when the “Merry Christmas” banner is completely off of the left side of the applet window that it starts to appear on the right side of the applet window again. Merry Christmas Everyone.

Link to Christmas Tree Applet source code