23 Dec 2011

Create A Smiley Face using JAVA applets.

Hey Guys. After my last article on JAVA I thought to add some more stuff into it. Last Month I got a problem of making an Smiley face using Applets in JAVA as assignment. Applets are really great tool for such animated programs. So I just thought to share it with you.

1) Click Start > run > type notepad

2) type the following code into it.

 import java.awt.*;
 import java.applet.*;
 public class MyApplet extends Applet
 {
  public void paint(Graphics g)
  {
   g.drawOval(100,50,200,200);
   g.drawOval(135,80,40,40);
   g.drawOval(220,80,40,40);
   g.drawLine(200,120,200,170);
   g.drawArc(148,106,100,100,-30,-120);
  }
 }


3) now save it as MyApplet.java
4) again open notepad and type the below code

     <html>
     <head><title>First Applet</title></head>
     <body>
     <applet code=MyApplet.class width=400 height=400>
     </applet>
     </body>
     </html>


5)  save it as xyz.html

6) The Next Step is to run java compiler. Open start > run > type cmd
7) In order to create byte code first go to specific location of your program then type:
      javac MyApplet.java
8) It is successfully compiled. To see your smiling face :P    in cmd window type:
      appletviewer xyz.html
 Here is a Snapshot.

Note: For any issues related with Program Compiling or JRE take a look at Compile JAVA program . For any queries related with concept of this program ping me on Facebook.


0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Online Project management