by Dinesh Thakur

There are four different overloaded drawImage methods in Graphics.

First, we'll show you the least complicated call:

if (image != null) {
   g.drawImage (image,xloc,yloc, this) ;
}
 
by Dinesh Thakur

The Java AWT provides several classes to manage loading and displaying images. The most common image code you see on the Web is called an animator. There are numerous animation applets and classes available on the WWW. The Java Developer's Kit provides a set of demo applications that draw images using static, single-buffered, and double-buffered animation.



 
by Dinesh Thakur

When you override the Container.insets () method, you are instructing the AWT to provide a margin around your container. The inset is used mostly by the Layout Manager to calculate sizing and positioning for contained objects. The Layout Manager will fit everything inside the insets you provide to it. The most common use of the inset space is to provide white space around a set of components to make them stand out as a group or just to provide more pleasing balance to a window.Remember that the insets indicate the distance from the border of the container to the contained objects. Effectively, you are setting the margins for your container. The space between the top, left, right, and bottom inset and the border of the container would be considered the margin.

 
by Dinesh Thakur

The AudioClip class is used to load and play sound files. To load a sound file the getAudioClip () Method of the AudioClip class is used. The general form of the getAudioClip () method is

 
by Dinesh Thakur

A rectangle can be drawn by using the drawRect () method. This method also takes the four parameters.

 
by Dinesh Thakur

Java allows the applet to transfer the control to another URL by using the showDocument () Method defined in the AppletContext interface. For this, first of all, it is needed to obtain the Context of the currently executing applet by calling the getAppletContext () method defined by the Applet. Once the context of the applet is obtained with in an applet, another document can be brought into view by calling showDocument () method.



 
by Dinesh Thakur

In Java, an event is an object which specifies the change of state in the source. It is generated whenever an action takes place like a mouse button is clicked or text is modified. Java's AWT (Abstract Window Toolkit) is responsible for communicating these actions between the program and the user. Java packages such as java. util, java. awt, java. awt. event and javax. swing support event handling mechanism.



 
by Dinesh Thakur

The AWT allows us to use various graphical components. When we start writing any applet program we essentially import two packages namely - java.awt and java.applet.



 
by Dinesh Thakur

The Graphics class provides different methods for drawing shapes such as lines, rectangles and ovals. Table shows the methods that are used to draw shapes. Each drawing method takes.

 
by Dinesh Thakur

The Abstract Windowing Toolkit (AWT) is the first set of nontrivial, publicly available, basic objects with which to build Java programs, with the focus on graphical user interfaces, or GUls. The AWT was built by Sun's JavaSoft unit and is provided free for anyone to use for any reason whatsoever, in binary form. There is some controversy as to whether the AWT in its present condition will survive, but it does have three things going for it:



 
by Dinesh Thakur

The APPLET tag of HTML is used to start an applet either from a web browser or an applet viewer. The HTML tag allows a Java applet to be embedded in an HTML document.



 
by Dinesh Thakur

Applets can be executed in two ways: from Browser or from Appletviewer. The JDK provides the Appletviewer utility.

 
by Dinesh Thakur

Java programs consist of applications and applets. Java applications are stand-alone programs and typically executed using the Java interpreter. On the other hand, Java applets are executed in a web browser or in a special window known as the Appletviewer; however, the compilation stages of both are the same.



 
 
by Dinesh Thakur

When a component receives focus, ie, is the element of the screen that is active FocusEvent type events occur. 

To make an object can listen to events FocusEvent FocusListener type must implement the interface, and it must be added as to the method FocusListener

 
by Dinesh Thakur

The AWT provides java.awt.TextField class through the component box input text or just text box. This component enables the editing and input a single line of text in a very convenient way for the user.Hence, this control is called editable control. Any data entered through this component is treated primarily as text, should be explicitly converted to another type if desired.



 
by Dinesh Thakur

The java.awt.MediaTracker class is a useful class.It can monitor the progress of any number of images, so you can expect to all images are loaded or to be loaded only specific. Furthermore, can check for errors. The constructor is: public MediaTracker (Component comp) This constructor creates a new MediaTracker for pictures to be displayed in the variable comp, but really this parameter is not particularly important. 



 
by Dinesh Thakur
 
by Dinesh Thakur

 The Image class is used to load and display images. To load an image the getimage ()method of the Image class is used and to display the image the draw Image ()method of the Graphics class is used.

 
by Dinesh Thakur

Usually java.awt.Image class can be used to display GIF (Graphics Interchange Format) or JPEG (Joint Photographic Experts Group.) One way to get a image is using the getImage method available in the Toolkit object that encapsulates  specific methods of the platform used, as below:



 
by Dinesh Thakur
 
by Dinesh Thakur
 
by Dinesh Thakur
 
 
 
 
by Dinesh Thakur

The java.awt.Canvas component is a "web" rectangular area for supporting drawing operations defined by the application as well as monitor input events performed by the user. This component does not encapsulate another feature except the support for rendering, providing a base class for creating new components.



 
by Dinesh Thakur

When the images are initially loaded, they are only partially displayed as they may not have been loaded completely. Mediatracker tracks the status of the number of media objects which includes audio clips as well as images. Secondly, it also determines if an image has been completely loaded.

 
by Dinesh Thakur

The MenuBar class encapsulates the platform's concept of a menu bar bound to a frame. In order to associate the menu bar with a Frame object, call the frame's setMenuBar method.

 
 
by Dinesh Thakur

The FontMetrics class is used to return the specific parameters for a particular Font object. An object of this class is created using the getFontMetrics() methods supported by the Component class and other classes, such as the Graphics and Toolkit classes. The FontMetrics access methods provide access to the details of the implementation of a Font object.

 
by Dinesh Thakur

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

The Color class is used to create colors in the default RGB color space or colors in any color spaces defined by a ColorSpace. Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor. The alpha value defines the transparency of a color and can be represented by a float value in the range 0.0 - 1.0 or 0 - 255. An alpha value of 1.0 or 255 means that the color is completely opaque and an alpha value of 0 or 0.0 means that the color is completely transparent. When constructing a Color with an explicit alpha or getting the color/alpha components of a Color, the color components are never pre multiplied by the alpha component.

 
by Dinesh Thakur

It is a subclass of the abstract InputEvent class and is generated when the user presses or releases a key or does both i.e. types a character.

 
by Dinesh Thakur

The addMouseMotionListener () method to handle events related to mouse movements. methods mouseDragged () and mouseMoved () receive events. Any of the objects of the Canvas, JDialog, JFrame, JPanel and JWindow classes can produce such events. To mark an object can listen to these events must implement the interface MouseMotionListener, and we have added the producer of events by the method:

public void addMouseMotionListener(MouseMotionListener mml)

 
by Dinesh Thakur

The MouseEvent event is used by two different interfaces:


java.awt.event.MouseListener and java.awt.event.MouseMotionListener. The first interface is designed to process events button press and mouse detection entrance and exit of a mouse over a component. The second is the processing the mouse movement.



 
by Dinesh Thakur

This component, known as multiline input box or memo, allows creation of an area for entering and editing text containing multiple lines in order to can even contain more text than can be displayed. Belongs to the class java.awt.TextArea and java.awt.TextField as the component shares the characteristics of their ancestral component java.awt.TextComponent.



 
by Dinesh Thakur

While single-line input is handled by TextField, many applications need to display and/ or edit larger bocks of text. TextArea is the AWT component that supports this feature. TextArea class provides a rectangular area (in rows and columns) for user interaction.

 
by Dinesh Thakur

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

Checkbox is used to indicate whether a thing is on or off, it's very common to use a group of them to indicate which one of many choices is active. This is the exact functional equivalent of a Choice object with static contents. In the AWT, a group of checkboxes used for a one-of-many control is called a CheckboxGroup. Many systems call this kind of control a radio button or other similar name.

 
by Dinesh Thakur

The repaint () method causes then AWT runtime system to execute the update () method of the Component class which clears the window with the background color of the applet and then calls the paint () method. But sometimes erasing the background is undesirable. For example: If user wants to display the x and y coordinates of each location where the mouse is clicked instead of only the currently clicked location then it is not possible using the default version of the update () method. Each time the user clicks in the applets's window, the coordinates of the previously clicked location are erased and only the coordinates of the currently clicked location are displayed. To overcome this problem, it is necessary to override the update () method to invoke paint () directly, thus avoiding the erasure of the component's background.

 
by Dinesh Thakur

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

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

Sometimes you may want to know the precise information about the font such as height, ascent, decent and leading etc. For example, if you want to display string in the center of the panel.



 
by Dinesh Thakur

In order to set a different font, Java provides the Font class contained in java. awt package. You can create the Font object using the following constructor.



 
by Dinesh Thakur

However, if you want to change the color of the text or GUI components, Java provides the Color class contained in java.awt.package. Every color is made up of red, green and blue components, each represented by an unsigned byte value that describes its intensity. You can specify the intensity of each color to be a value ranging from 0 to 255 where 0 represents the darkest shade and 255 represents the lightest shade. This is known as RGB model.



 
by Dinesh Thakur

A popupmenu is a small window that pops up and displays a list of choices such as Cut, Copy, Paste, Select All etc. This menu is invisible until the user makes a platform specific mouse action such as pressing the right mouse button over a popup enabled component. The popup menu then appears under the cursor.

 
by Dinesh Thakur

Creating a menu bar is straight forward. You have to simply create an instance of Java.awt.MenuBar which is a container for menus. It has only one constructor which is the default constructor as follows,



 
by Dinesh Thakur

The java.awt.GridBagLayout layout manager is the most powerful and flexible of all the predefined layout managers but more complicated to use. Unlike GridLayout where the component are arranged in a rectangular grid and each component in the container is forced to be the same size, in GridBagLayout, components are also arranged in rectangular grid but can have different sizes and can occupy multiple rows or columns.



 
by Dinesh Thakur

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

The GridLayout layout manager divides the container into a rectangular grid so that component can be placed in rows and column. The intersection of each row and column is known as a cell. The components are laid out in cells and each cell has the same size, components are added to a GridLayout starting at the top left cell of the grid and continuing to the right until the row is full. The process continues left to right on the next row of the grid and so on.

 
by Dinesh Thakur

The BorderLayout layout manager divides the container into five regions that are named geographically: Top (north), lower (south), left (west), right (east) and central (center). North corresponds to the top of the container. You can add only one component per region to a container controlled by a BorderLayout layout manager. However, this limitation can be overcome by adding a container with multiple components (such as Panel). Components laid out by this layout manager normally do not get to have their preferred size.

 
by Dinesh Thakur

The FlowLayout is one the most popular and simplest layout manager. It places components in a container from left to right in the order in which they were added to the container. When one row is filled, layout advances to the next row. It is analogous to lines of text in a paragraph. Components managed by a FlowLayout are always set to their preferred size (both width and height) regardless of the size of the parent container. Whenever the container is resized then the components in the container are also adjusted from the top-left comer. The FlowLayout is the default layout manager for a Panel, Applet and JPanel.

 
by Dinesh Thakur

How does Java come to know where to place the component into the container. One possible way is to tell it manually. By manually, we mean that you have to specify the size and position of each component yourself.



 
by Dinesh Thakur

The java.awt.Panel or Panel is a container that is designed to group a set of components, including other panels. It is visually represented as window that does not contain a title bar, menu bar or border. Panels are represented by objects created from Panel class by calling the constructor. The java.awt.Panel class has two constructors:



 
by Dinesh Thakur

A scrollbar is a component that allows a user to select any numeric value by dragging a slider within a range defined by a minimum and maximum. A scrollbar may be oriented horizontally or vertically. A scrollbar consists of several individual parts: arrows (the buttons at each end of the scrollbar), a slider box or thumb (scrollable box you slide) and a track (part of the scrollbar you slide the thumb in).

 
by Dinesh Thakur

The java.awt.List component , known as a listbox or list box,  is similar to the Choice component, except it shows multiple items at a time and user is allowed to select either one or multiple items at a time. When the numbers of items in the list exceed the available space, the scrollbar will be displayed automatically. A list can be created by instantiating a List class.



 
by Dinesh Thakur

The Choice component is a combination of textfield and drop down list of items. User can make selection by clicking at an item from the list or by typing into the box. Note that you cannot select multiple items from the list. This component is the best component to use than the check box groups or list because it consumes less space than these components. It can be created by instantiating the Choice class. Choice has only one default constructor, namely the following.

 
by Dinesh Thakur

A check box group is a set of checkboxes in which one and only one checkbox can be checked at anyone time. Any other previously selected checkbox in the group is unchecked. These checkboxes are sometimes called radio buttons.

 
by Dinesh Thakur

The check box, as it is also known java.awt.Checkbox component is a component used to plot an option which can be connected (on ​​= true) or off (off = false). It is usually used to display a set of options which can be selected independently by the user, or allow multiple selectionsThese controls also have a label associated with them which describes the option of the checkbox. This control supports many constructors.



 
by Dinesh Thakur

Buttons are perhaps the most familiar of all the component types. It is a regular push button that can contain text. It can be created by instantiating the Button class. The text on the face of the button is called button label. The buttons, components encapsulated in java.awt.Button class are as panels labeled with a text that, when activated, can trigger the execution of a routine or sequence of commands. Whenever a push button is clicked, it generates an event and executes the code of the specified listener. A button can be created using the following syntax:

Button button=new Button( );
Button button=newButton(String button name);

Button objects provide the most basic (and most commonly used bi-state controls in the AWT. They are generally labeled with SUBMIT, YES, ACCEPT, NO, or other simple one- or two word messages. Very seldom are AWT Buttons sub classed in a normal application.

A Button is added to a Container object (usually a Panel or a descendant of Panel) and is then said to be contained or owned by the Panel. The event handler for the Panel is normally considered to be responsible for any actions upon the Button.

 

Button Useful Interface

 

Metohod

Returns

Notes

Button

 

 

Button(String label)

 

An empty Button is somewhat unusual, but possible

getLabel()

String

What’s on the Button right now?

setLabel(String label)

Void

Paint a new text string in same Button; this implies a layout manager relayout

 

import java.awt.*;

class ButtonExample extends Frame
{
     ButtonExample()
     {
         setLayout(new FlowLayout());     
         Button btnOK = new Button("OK");
         add(btnOK);
     }
}
    class ButtonsJavaExample
   {
       public static void main(String args[])
      {   
           ButtonExample frame = new ButtonExample();
           frame.setTitle("Buttons in Java Example");
           frame.setSize(250,100);
           frame.setResizable(false);
           frame.setVisible(true);
     } 
   }

Buttons in Java Example



 
by Dinesh Thakur

The TextArea component is similar to the TextField component except that it allows to display and edit multiple lines of plaintext. The TextArea component has certain number of rows and columns that determines its size. If all the text cannot be displayed in the available space in the component, even then scrollbars are not automatically added. In order to add scrollbars, you must insert it into a Scrollpane.

 
by Dinesh Thakur

A Textfield is a component used for displaying, inputting and editing a single line of plain text. We can create textfield by creating an instance of Textfield class. The TextComponent is a superclass of TextField that provides common set of methods used by Textfield.

 
by Dinesh Thakur

Labels are the simplest of all the AWT components. A label is a component that may contain uneditable text. They are generally limited to single-line messages (Labels, short notes, etc.). They are usually used to identify components. For example: In large GUI, it can be difficult to identify the purpose of every component unless the GUI designer provides labels (i.e. text information stating the purpose of each component).



 
by Dinesh Thakur

In this java Example, we have created a class named MyFrame that extends the Frame class. The constructor of the MyFrame class contains the statements that constructs the user interface.



 
by Dinesh Thakur

In order to add a component to a container, first create an instance of the desired component and then call the add () method of the Container class to add it to a window. The add () method has many forms and one of these is.

 
by Dinesh Thakur

The java.awt.Frame component is a Windows graphics system which has a title bar and borders, behaving like a normal GUI window. How is a subclass of java.awt.Container can contain other components being that its primary purpose. The default alignment components added to a Java.awt.BorderLayout.

When working with Frame objects, the following steps are basically followed to get a window to appear on the screen.



 
by Dinesh Thakur

The color class is used to manipulate colours using the methods and constants defined in it. Every colour is a combination of red, green and blue. Combinations of these three colours, which take values from 0 to 255 or 0.0 to 1.0, can generate any new colour. Therefore, the Color class has two constructors, one takes integer parameters and another takes float parameters.

 
by Dinesh Thakur

getWidth and getHeight are predefined abstract methods present in Image class. getWidth method determines the width of an image. getHeight method determines the height of an image. Return type of this two method are int type. Syntax- public abstract int get Width (java.awt.image.    ImageObserver) public abstract int get Height java.awt.image. ImageObserver).



 
by Dinesh Thakur

addWindowListener method is used to add the windowlistener interface to the window. WindowClosing is a predefined method of WindowListener interface present in java.awt package. exit is a predefined static method present in System class, used to terminate the currently running java. syntax-public static void exit (int status)



 
by Dinesh Thakur

JFrame class is a predefined class present in javax.swing package. setLayout method is a predefined method present in JFrame class used to set the layout the frame.  BufferedImage class is a predefined class present in java.awt.image package. getGraphics method is a predefined method present in BufferedImage class. Return type of this method is Graphics class object. Syntax-public Graphics getGraphics ().



 
by Dinesh Thakur

In the Following example ChangeCursor shows how to Changing the Cursor in Java with  setCursor() method defined in the Component class. setCursor method is used to changes the cursor icon when the cursor goes upon the particular component. and the getPredefinedCursor() method returns the cursor object to be specified in the cursor block. Changing Cursor means showing cursor in many different  shapes when the cursor goes upon the particular component.



 
by Dinesh Thakur

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)

 
by Dinesh Thakur

Following example SmileExample shows how to Smily face using an Applet window with drawArc,fillArc, drawLine,fillOval drawOval method of Graphics class.

 
by Dinesh Thakur

In most of the applets, it is required to load text and images explicitly. Java enables loading data from two directories. The first one is the directory which contains the HTML file that started the applet (known as the document base). The other one is the directory from which the class file of the applet is loaded (known as the code base). These directories can be obtained as URL objects by using getDocumentBase ()and getCodeBase ()methods respectively. You can concatenate these URL objects with the string representing the name of the file that is to be loaded.



 
by Dinesh Thakur

Eample AppletDimension print center aligned text "Hello Java" This Java example 'How to Set the Dimension of the Applet' shows how to print a string in center of an applet screen window using the Dimension class.



 
by Dinesh Thakur

In the Following example PixelsApplet shows how to Fill Screen With Pixel in Applet windows Example and set color of an Applet window using setColor(),Random(), method of Graphics class for color the screen. Following example demonstrates how to Random setcolor with RGB values, for this you can use a Color object.

 
by Dinesh Thakur

In the Following example DashedStrokeApplet shows how to Draw Dashed Stroke Polygon Applet Window Example using Graphics2D class and setPaint(),setStroke(),BasicStroke() method of Graphics class. The Syntax for drawPolygon(int[] xPoints, int[] yPoints, int numPoint); and The Syntax for BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) ; setStroke is an inteface defined in the java.awt package.



 
by Dinesh Thakur

In the Following example DashedLinesApplet shows with Basic Stroke how to Draw Dashed Line in Applet and set foreground color of an Applet window using Graphics2D class and setPaint(),setStroke(), BasicStroke() method of Graphics class. The Syntax for BasicStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) ; setStroke is an inteface defined in the java.awt package.



 
by Dinesh Thakur

In the Following example Draw Image in Applet shows how to Draw Image on Applet window using getDefaultToolkit(),drawImage(), method of Graphics class. To draw the images, we use java.awt.Graphics package comes with a drawImage() of Graphics class. The syntax for drawImage(image, int x, int y);



 
by Dinesh Thakur

A polygon is a closed geometrical figure which can have any number of sides. A polygon can be drawn by using the drawPolygon () method. This method takes three parameters.

 
by Dinesh Thakur

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

DrawOval The method can be used to draw ellipses or circles of  drawRect manner analogous to the method, ie by defining the location of the vertex  upper left (x, y) of the rectangle which fits the definition of ellipse and its width  width and height height, as indicated

In the Following example AppletDrawOval shows how to Draw Oval or Fill Oval and set foreground color of an Applet window using drawOval , fillOval, method of Graphics class.

 
by Dinesh Thakur

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

An arc can be drawn using the drawArc () method. This method takes six arguments in which the first four are same as the arguments of the drawoval () method and the next two represents the starting angle of the arc and the sweep angle around the arc, respectively.

 
by Dinesh Thakur

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

In this shapeDrawingApplet program we see how to draw the different shapes like line, circle and rectangle.

 
by Dinesh Thakur

In this showStatusMessage example You can see an message is shown on the Status bar of  applet.

 
by Dinesh Thakur

In this CommandLineApplet example You can see an applet program run from command Line without using any web browser.

 
by Dinesh Thakur

An applet is a class file that is specially written to display graphics in a web browser. Applets are embedded in web pages using the HTML tag <Applet>. Java applets are downloaded automatically and run by the web browser. Any web-browser that supports Java, such as Applet Viewer, can be used to transport applets to the Internet. An applet can perform many functions such as graphics, play sound, animation, arithmetic operations, play games etc.



 
by Dinesh Thakur

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

An applet can output a message to the status window of the browser or applet viewer on which it is running. For this, it makes a call to showStatus( ) with the string that we want to be displayed. The status window is a place where the user can give feedback about what is occurring in the applet, suggest options, or report some types of errors. The status window also makes an excellent debugging aid, because it gives an easy way to output information about the applet. The applet below shows the use of showStatus( ):



 
by Dinesh Thakur

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

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

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:



 

Page 1 of 2