Java examples
Home
Welcome to
Java Examples
Take a cup of tea and Let's Start programming
create smiley using thread and different drawing methods of paint
import java.applet.Applet; import java.awt.*; public class smiley extends Applet implements Runnable { int x=1; Thread t; public void init() { t = new Thread(this); t.start(); } public void run() { try{ while(true) { repaint(); Thread.sleep(1000); } } catch(Exception e) {} } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { setForeground(Color.yellow); g.fillOval(50,75,250,250); g.setColor(Color.white); g.fillOval(85,135,70,30); g.fillOval(195,135,70,30); g.setColor(Color.black); if(x==1) { g.fillArc(140,250,25,25,160,170); g.fillOval(100,135,20,30); g.fillOval(210,135,20,30); g.drawArc(170,225,15,5,180,180); x=2; } else { g.fillArc(145,259,25,25,180,180); g.fillOval(125,135,20,30); g.fillOval(225,135,20,30); g.drawArc(165,225,15,10,180,180); x=1; } } }
output
Newer Post
Older Post
Home
0 comments :
Post a Comment
Search Form
Popular Posts
Design a class named Fan to represent a fan....
abstract class
program to display employee who have salary more than 20000
Define the Rectangle class
Logic behind pattern...
0 comments :
Post a Comment