by Dinesh Thakur Category: AWT and Applets

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

Here is the java code for the program SmileExample :.

 

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
 
public class SmileExample extends Applet{
public static void main(String[] args) {
Frame AppletSmileExample = new Frame("Draw Smiley in Applet Example");
AppletSmileExample.setSize(350, 250);
Applet SmileExample = new SmileExample();
AppletSmileExample.add(SmileExample);
AppletSmileExample.setVisible(true);
AppletSmileExample.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
      }
    });
  }
        public void paint(Graphics g){
                g.setColor(Color.darkGray);
                g.setFont(new Font("Arial",Font.BOLD,14));
                g.drawString("Draw Smiley In Applet Example ", 50, 40);
                g.setFont(new Font("Arial",Font.BOLD,10));
                g.drawString("http://ecomputernotes.com", 200, 205);
               
            
                //The Syntax for drawOval(int xTopLeft, int yTopLeft, int width, int height);
                g.drawOval(70, 50, 150, 150);
                //The Syntax for fillOval(int xTopLeft, int yTopLeft, int width, int height);
                g.fillOval(80, 100, 50, 20);
                g.fillOval(160, 100, 50, 20);
              
                //Syntax For:- drawString(String str, int xBaselineLeft, int yBaselineLeft);
                g.drawLine(145, 125, 145, 155);
                //Syntax For:- drawArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle);
                g.drawArc(100, 90, 95, 95, 0, -180);  
        }
}

Draw Smiley in Applet Example



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