Home / JAVA / Java Applet With Its Functions

Java Applet With Its Functions

Java Applet

applet
image source:-http://1.bp.blogspot.com

An applet is a Java programming language that provides a small window to manage the components with graphics. An applet is the feature of java that provides graphical tools to interact with the user and process the instructions. The applet executes and attached with HTML tag.

Applet Class:- Applet Class is a class that available in java.applet package. It provides built-in functions to manage the graphical process and provide a window.

 

Functions of Java Applets

 

  1. Paint():- It is a function that provides a window and initialized small window and allows to define the graphic symbol like circle etc. In this, we pass the object of graphics class.
  2. Graphics Class():- It is a class that available in java.awt package. It provides built-in functions to define the graphics.
  • drawString():- It is a function that displays the message at a particular position on the applets. In this, we pass a message, x-coordinate, and y-coordinate as an argument.
  •  drawRect():- It is a function that draws a rectangle on the base of given coordinates. In this, we pass x-coordinate, y-coordinate, width and height as an argument.
  • drawOval():- It is used to draw the oval on the base of given coordinates. In this, we pass x-coordinate, y-coordinate, width and height as an argument.
  • drawLine():- It is used to draw the line. In this, we pass start x, start y, end x, end y.
  • drawArc():- It draws the arc with x-coordinate, y-coordinate, width, height, start angle and end angle.

 

Syntax:-

/* <applet code = demo  height=400  width=400 >

</applet>

*/

 

Example:-

import java.awt.*;

import java.applet.*;

public Class demo extends Applet

{

    public void paint ( Graphics g)

     {

          g.drawString ("Hello", 100, 100);

           g.drawLine (100, 10, 10, 100);

           g.drawRect (100, 100, 50, 50);

            g.drawOval (200, 100, 50, 50);

                }

}

 

For saving File: demo.java

For compiling: javac demo.java

For running: appletViewer demo.java

 

Font Class

Font class is a class that allows setting the font of particular text. We use font class to define the font name, font style.

Constructor (String, int, int)

It is a construction of font class that allows setting the font of particular text. In this, we define font name, font style, and font size respectively.

  1. setFont():- It is the function of awt class that allows setting the font and we pass the object of font class.
     Example:-

         g.setFont( "Jokerman", Font.BOLD, 20);

2. setColor():- It is used to set the color or graphics. In this, we pass the object of the color class. Color is a class that allows setting the color for components. We can combine color with the help of numeric value. In this, we define 3 integer argument between 0 to 255.

3. fillRect():- It is used to draw the rectangle and fill the existing color also.

4. fillOval():- This function creates the oval and fills with existing color.

 

Example:-

import java.awt.*;

import java.applet.*;

public Class demo extends Applet 

{

   public void paint ( Graphics g)

   {

       g.setFont ( new Font ( "Thomb", Font.BOLD, 30));

       g.drawString ("Hello", 100, 100);

       g.setColor ( new Color (255, 00, 225));

        }

}

 

 

About Udit Mutreja

Check Also

Java For Loop

Loops Statement: The programming instructions are defined in a sequence and perform on the base …

Leave a Reply

Your email address will not be published. Required fields are marked *