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

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

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 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.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

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:



 
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

In the Following example AppletDrawRect shows how to Draw Rectangle or Fill Rectangle and draw filled rounded corner rectangle or set foreground color of an Applet window using drawRect,fillRect, drawRoundRect, fillRoundRect method of Graphics class. The Syntax for The Syntax for drawRect(int xTopLeft, int yTopLeft, int width, int height); and The Syntax for fillRect(int xTopLeft, int yTopLeft, int width, int height); and The Syntax for round cornered square drawRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int arcHeight), and The Syntax for fillRoundRect(int xTopLeft, int yTopLeft, int width, int height, int arcWidth, int arcHeight)

 
by Dinesh Thakur Category: AWT and Applets

Applets are displayed in a window and they use the AWT to perform input and output functions. To output a string to an applet, use drawString( ), which is a member of the Graphics class. Typically, it is called from within either update() or paint( ). It has the following general form:

 
by Dinesh Thakur Category: AWT and Applets

In the Following Draw3DRectExample shows how to Draw 3DRect or Fill 3DRect using draw3DRect,fill3DRect method of Graphics class. The Syntax for draw3DRect(int x_coordinates,int y_coordinates, int width, int height, boolean raised) and The Syntax for fill3DRect(int x_coordinates,int y_coordinates, int width, int height, boolean raised)

 

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.



Search Content







Popular Article