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 Applications and Components

In order to better understand how a Java Program works, let’s look at an example, the Painter program.
Painter Program Screenshot
The Painter Program allows the user to draw a picture in the program window using the color blue by clicking and holding the left mouse button and to delete parts of what they have drawn by clicking and holding the right mouse button. Like all Java Programs the Painter program has a main method which is where the program begins execution. There is also a method designed to draw the program window and user interface on the screen called createUserInterface. There is also a mouseListener which checks to see if the mouse was clicked, entered the program window, exited the program window, was pressed, or was released. There are also a few additional methods that facilitate drawing onto the program window. There are two classes in the Painter program. The Painter class, which has the main method as well as the createUserInterface method, and the DrawJPanel class, which handles checking for mouse releases clicks and mouse button releases and handles drawing to the program window. The control flow of the Painter program is fairly simple to understand. When the Painter Program is first loaded, the main method is where the program starts to execute. The main method creates and sets up the window for the program. Once the main method is done setting up the program window, the program simply waits for the user to move the mouse or click the mouse. If the program detects that the user wants to draw on the window, it gets the location of the mouse press, and draws a small draw circle there. If the program detects that the user wants to erase some thing on the window, it draws a small circle of the same color of the background at the location of the mouse press. That is really all there is too it.

Link to Painter class source code
Link to DrawJPanel class source code