by Dinesh Thakur Category: AWT and Applets

Java applet inherits features from the class Applet. Thus, whenever an applet is created, it undergoes a series of changes from initialization to destruction. Various stages of an applet life cycle are depicted in the figure below:

 
by Dinesh Thakur Category: AWT and Applets

When an applet is executed within the web browser or in an applet window, it goes through the four stages of its life cycle: initialized, started, stopped and destroyed. These stages correspond to the applet methods init (), start (), stop () and destroy () respectively. All these methods are defined in the Applet class which are called automatically by the browser or the applet viewer controlling the applet. All these methods have empty bodies by default. To perform specific functions, these methods need to be overridden in the user's applet so that the browser can call your code properly.

 
by Dinesh Thakur Category: AWT and Applets

The DrawLine method can be used for drawing straight lines between two points (x1, y1) and (x2, y2) data. Following example DrawLine shows how to  Draw a Line on Applet window using drawLine method of Graphics class.

 
by Dinesh Thakur Category: AWT and Applets

The paint () method is called automatically by the environment (usually a web browser) that contains the applet whenever the applet window needs to be redrawn. This happens when the component is first displayed, but it can happen again if the user minimizes the window that displays the component and then restores it or if the user moves another window over it and then move that window out of the way. In addition to these implicit calls to the paint() method by the environment, one can also call the paint () method explicitly whenever the applet window needs to be redrawn, using the repaint () method.

 
by Dinesh Thakur Category: AWT and Applets

The java.awt.Choice component implements a list of items where only the selected item is displayed. The list appears as a drop down (pop-down menu) menu can  be seen through the touch of a button built into the component, so it is  also known as a check box or combobox. In the same manner as in  component java.awt.List a vertical scrollbar is automatically displayed  when the list can not simultaneously show all the items they contain. The selection  only operate in simple mode, that is, only one item can be selected at a time,  and the choice of an item not selected selects and vice versa.



 
by Dinesh Thakur Category: AWT and Applets

The Font class provides a method of specifying and using fonts. The Font class constructor constructs font objects using the font's name, style (PLAIN, BOLD, ITALIC, or BOLD + ITALIC), and point size. Java's fonts are named in a platform independent manner and then mapped to local fonts that are supported by the operating system on which it executes. The getName() method returns the logical Java font name of a particular font and the getFamily() method returns the operating system-specific name of the font. The standard Java font names are Courier, Helvetica, TimesRoman etc.



 
by Dinesh Thakur Category: AWT and Applets

Java allows users to pass user-defined parameters to an applet with the help of <PARAM>tags. The <PARAM>tag has a NAME attribute which defines the name of the parameter and a VALUE attribute which specifies the value of the parameter. In the applet source code, the applet can refer to the parameter by its NAME to find its value. The syntax of the <PARAM>tag is:

 
by Dinesh Thakur Category: AWT and Applets

The Color class provides various methods to use any color you want in display. It defines various color constants which can be directly used only by specifying the color of your choice. In addition, the Color class allows creation of millions of colors. The Color class contains three primitive colors namely, red, blue and green and all other colors are a combination of these three colors. One of the constructors that is used to create color of your choice is

 
by Dinesh Thakur Category: AWT and Applets

The java.awt.CardLayout layout manager is significantly different from the other layout managers. Unlike other layout managers, that display all the components within the container at once, a CardLayout layout manager displays only one component at a time (The component could be a component or another container).



 
by Dinesh Thakur Category: AWT and Applets

One of the important architectural constraints that have been imposed on an applet is that it must quickly return control to the AWT run-time system. It cannot create a loop inside paint( ). This would prevent control from passing back to the AWT. Whenever your applet needs to update the information displayed in its window, it simply calls repaint( ). The repaint( ) method is defined by the AWT that causes AWT run-time system to execute a call to your applet's update() method, which in turn calls paint(). The AWT will then execute a call to paint( ) that will display the stored information. The repaint( ) method has four forms. The simplest version of repaint( ) is:



 

Page 1 of 11



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles