BablaDemo.java
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=BablaDemo height=400 width=400>
</applet>*/
public class BablaDemo extends Applet implements MouseMotionListener,MouseListener
{
int flag=0;
public void init()
{
addMouseMotionListener(this);
addMouseListener(this);
}
public void paint(Graphics g)
{
if(flag==0)
{
g.drawOval(160,100,90,70); //head
g.drawLine(205,170,205,330); //body line
g.drawLine(205,330,140,375); //left leg
g.drawLine(205,330,270,375); //right leg
g.drawLine(205,225,140,255); //left hand
g.drawLine(205,225,270,258); //right hand
g.drawOval(180,126,10,10); //left eye
g.drawOval(220,126,10,10); //right eye
}
else
{
g.drawOval(160,100,90,70); //head
g.drawLine(205,170,205,330); //body line
g.drawLine(205,330,140,345); //left leg
g.drawLine(205,330,270,345); //right leg
g.drawLine(205,225,140,220); //left hand
g.drawLine(205,225,270,223); //right hand
g.drawOval(180,126,10,10); //left eye
g.drawOval(220,126,10,10); //right eye
g.drawLine(205,125,205,145); //nose
}
}
public void mouseDragged(MouseEvent me)
{
showStatus("Mouse Dragged");
}
public void mouseMoved(MouseEvent me)
{
showStatus("x ="+me.getX()+" "+"Y ="+me.getY());
}
public void mousePressed(MouseEvent me)
{
if(flag==0)
{
flag=1;
repaint();
}
else if(flag==1)
{
flag=0;
repaint();
}
}
public void mouseEntered(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
if(flag==0)
{
flag=1;
repaint();
}
else if(flag==1)
{
flag=0;
repaint();
}
}
}
When You Click On this Imag It's Look Like as Dance...
Note :- Run this program Step 1.java BablaDemo.java
Step 2appletviewer BablaDemo.java
No comments:
Post a Comment