Java Applet Program to Draw Human Smiley Face
Tip Abstraction:
This is a simple Java applet program for getting output of a human smiley face with customization
We can make any type of smileys face by Java applet program codes. This java program shows how to make a normal human smiley face icon. But these are not similar to original smileys. But by doing this type of Java Applet programs, you can familiarize to X,Y coordinate of graphics.
import java.applet.*; import java.awt.*; /* <applet code = "face" width = 300 height = 300> </applet> */ public class face extends Applet { public void paint(Graphics g) { g.drawOval(100,100,100,100); g.fillOval(120,125,20,20); g.fillOval(160,125,20,20); g.drawLine(150,165,150,150); g.drawLine(130,170,170,170); } } |
You can declare the color in variable ‘g’. Example: g.setColor(Color.yellow);
Then all color using ‘g’ should be ‘yellow’ until setting a new color.
Colorful smiley:
import java.applet.*; import java.awt.*; /* <applet code = "face" width = 300 height = 300> </applet> */ public class face extends Applet { public void paint(Graphics g) { g.setColor (Color.yellow); g.fillOval (100,100,100,100); g.setColor (Color.black); g.fillOval (120,125,20,20); g.fillOval (160,125,20,20); g.setColor (Color.blue); g.drawLine (150,165,150,150); g.drawLine (130,170,170,170); } } |
Output:
Another smiley:
import java.applet.*; import java.awt.*; /* <applet code = "face" width = 300 height = 300> </applet> */ public class face extends Applet { public void paint(Graphics g) { g.setColor (Color.yellow); g.fillOval (100,100,100,100); g.setColor (Color.black); g.fillRect (120,125,20,20); g.fillRect (160,125,20,20); g.drawLine (135,135,160,135); g.setColor (Color.red); g.drawLine (150,165,150,150); g.drawLine (130,170,170,170); } } |
import java.applet.*; import java.awt.*; /* <applet code = "face" width = 300 height = 300> </applet> */ public class face extends Applet { public void paint(Graphics g) { g.setColor (Color.yellow); g.fillOval (100,100,100,100); g.setColor (Color.black); g.fillOval (120,125,20,30); g.fillOval (160,125,20,30); g.setColor (Color.black); g.drawLine (150,165,150,150); g.setColor (Color.red); g.fillRect (130,170,40,10); g.setColor (Color.black); g.drawLine (131,174,169,174); } } |
applet not initialized
ReplyDeleteTry with both applet viewer and browser. if not working, recode and try. Above code works well in my PC
Delete