import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="paintbrush" width=500 height=400>
</applet>
*/
public class paintbrush extends Applet implements MouseListener,MouseMotionListener
{
String msg=" ";
int mouseX, mouseY,x,y,a,b,x1,y1;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{msg="mouse clicked";
repaint();
}
public void mouseReleased(MouseEvent me)
{
if(me.getX()>mouseX && me.getY()>mouseY)
{
x=me.getX()-mouseX;
y=me.getY()-mouseY;
}
else if(me.getX()<mouseX && getY()>mouseY)
{
x1=me.getX();
y1=me.getY();
x=mouseX-me.getX();
y=me.getY()-mouseY;
}
else if(me.getX()>mouseX && me.getY()<mouseY)
{
x1=me.getX();
y1=me.getY();
x=me.getX()-mouseX;
y=mouseY-me.getY();
}
else if(me.getX()<mouseX && me.getY()<mouseY)
{
x1=me.getX();
y1=me.getY();
x=mouseX-me.getX();
y=mouseY-me.getY();
}
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
x1=mouseX;
y1=mouseY;
}
public void mouseDragged(MouseEvent me)
{
if(me.getX()>mouseX && me.getY()>mouseY)
{
x=me.getX()-mouseX;
y=me.getY()-mouseY;
}
else if(me.getX()<mouseX&& me.getY()>mouseY)
{
x1=me.getX();
y1=mouseY;
x=mouseX-me.getX();
y=me.getY()-mouseY;
}
else if(me.getX()>mouseX && me.getY()<mouseY)
{
x1=mouseX;
y1=me.getY();
x=me.getX()-mouseX;
y=mouseY-me.getY();
}
else if(me.getX()<mouseX && me.getY()<mouseY)
{
x1=me.getX();
y1=me.getY();
x=mouseX-me.getX();
y=mouseY-me.getY();
}
repaint();
}
public void mouseEntered(MouseEvent me){
a=0;
b=10;
msg="mouse Entered";
repaint();
}
public void mouseExited(MouseEvent me){
a=0;
b=10;
msg="mouse exited";
repaint();
}
public void mouseMoved(MouseEvent me)
{
a=0;
b=10;
msg="mouse moved";
}
public void paint(Graphics g)
{
g.drawOval(x1,y1,x,y);
g.drawString(msg,a,b);
}
}
import java.awt.event.*;
import java.applet.*;
/*
<applet code="paintbrush" width=500 height=400>
</applet>
*/
public class paintbrush extends Applet implements MouseListener,MouseMotionListener
{
String msg=" ";
int mouseX, mouseY,x,y,a,b,x1,y1;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{msg="mouse clicked";
repaint();
}
public void mouseReleased(MouseEvent me)
{
if(me.getX()>mouseX && me.getY()>mouseY)
{
x=me.getX()-mouseX;
y=me.getY()-mouseY;
}
else if(me.getX()<mouseX && getY()>mouseY)
{
x1=me.getX();
y1=me.getY();
x=mouseX-me.getX();
y=me.getY()-mouseY;
}
else if(me.getX()>mouseX && me.getY()<mouseY)
{
x1=me.getX();
y1=me.getY();
x=me.getX()-mouseX;
y=mouseY-me.getY();
}
else if(me.getX()<mouseX && me.getY()<mouseY)
{
x1=me.getX();
y1=me.getY();
x=mouseX-me.getX();
y=mouseY-me.getY();
}
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
x1=mouseX;
y1=mouseY;
}
public void mouseDragged(MouseEvent me)
{
if(me.getX()>mouseX && me.getY()>mouseY)
{
x=me.getX()-mouseX;
y=me.getY()-mouseY;
}
else if(me.getX()<mouseX&& me.getY()>mouseY)
{
x1=me.getX();
y1=mouseY;
x=mouseX-me.getX();
y=me.getY()-mouseY;
}
else if(me.getX()>mouseX && me.getY()<mouseY)
{
x1=mouseX;
y1=me.getY();
x=me.getX()-mouseX;
y=mouseY-me.getY();
}
else if(me.getX()<mouseX && me.getY()<mouseY)
{
x1=me.getX();
y1=me.getY();
x=mouseX-me.getX();
y=mouseY-me.getY();
}
repaint();
}
public void mouseEntered(MouseEvent me){
a=0;
b=10;
msg="mouse Entered";
repaint();
}
public void mouseExited(MouseEvent me){
a=0;
b=10;
msg="mouse exited";
repaint();
}
public void mouseMoved(MouseEvent me)
{
a=0;
b=10;
msg="mouse moved";
}
public void paint(Graphics g)
{
g.drawOval(x1,y1,x,y);
g.drawString(msg,a,b);
}
}
No comments:
Post a Comment