The following example illustrates the use of Java applets through the java.applet package. The example also uses classes from the Java Abstract Window Toolkit (AWT) to produce the graphical output.
How it works?
1. First type in the source code and save it into file named Levis.java.
import java.awt.*;
public class Levis extends java.applet.Applet {
Font font=new Font("Arial Black",Font.BOLD,80);
Font font1=new Font("Arial Black",Font.BOLD,25);
Font font2=new Font("Goudy Old Style",Font.BOLD,35);
Font font3=new Font("Times New Roman",Font.BOLD,13);
int x[]={50,450,450,410,410,90,90,50};
int y[]={130,130,130,320,320,320,320,130};
public void paint(Graphics g){
g.setColor(Color.black);
g.fillRect(100,80,300,300);
g.setColor(Color.white);
g.fillRect(100,127,300,4);
g.setColor(Color.red);
g.fillPolygon(x,y,8);
g.setColor(Color.white);
g.fillOval(399,155,19,19) ;
g.setColor(Color.red);
g.fillOval(401,157,15,15) ;
g.setFont(font3);
g.setColor(Color.white);
g.drawString("R",404,168);
g.setColor(Color.white);
g.fillArc(90,295,160,50,0,180);
g.fillArc(250,295,160,50,0,180);
g.setColor(Color.black);
g.fillArc(92,299,157,47,0,180);
g.fillArc(252,299,157,47,0,180);
g.setFont(font);
g.setColor(Color.white);
g.drawString("LEVI'S",100,230);
g.setFont(font1);
g.setColor(Color.white);
g.drawString("LEVI STRAUSS & CO.",100,270);
g.setColor(Color.white);
g.fillOval(90,312,15,15) ;
g.setColor(Color.black);
g.fillRect(100,312,10,20);
g.setColor(Color.white);
g.fillRect(89,319,5,5);
g.setColor(Color.white);
g.fillOval(396,310,15,15) ;
g.setColor(Color.black);
g.fillRect(390,311,10,20);
g.setColor(Color.white);
g.fillRect(410,319,5,5);
g.setFont(font2);
g.setColor(Color.white);
g.drawString("O R I G I N A L",130,120);
g.setFont(font2);
g.setColor(Color.white);
g.drawString("R I V E T E D",146,360);
}
}
2. Compile this file in the usual way. If all is well a file called Levis.class will be created. Now you need to create an HTML file that will include your applet. The following simple HTML file will do.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "Levis.class"
width = "500"
height = "300">
</applet>
</center>
</body>
</html>
3. Save this file as Logo.html in the same directory as the Levis.class file. Then run the Logo.html using any Internet Browser or JCreator IDE.
Programming Language: Java
Programming IDE: JCreator