Pages

Java Tutorials

Java Tutorials
Java Tutorials

Wednesday, 6 November 2013

MOUSE LISTENER IN AWT PACKAGE

import java.applet.Applet;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
public class Mouse1 extends Applet implements MouseListener,MouseMotionListener
{
String txt="Nothing";
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}

public void mouseClicked(MouseEvent me)
{
txt="Mouse clicked";
setBackground(Color.RED);
setBackground(Color.GREEN);
repaint();
}

public void mouseEntered(MouseEvent me)
{
txt="Mouse Entreed";
setBackground(Color.BLUE);
setBackground(Color.YELLOW);
repaint();
}

public void mouseReleased(MouseEvent me)
{
setBackground(Color.YELLOW);
setBackground(Color.YELLOW);
txt="Mouse Released";
repaint();
}
public void mouseExited(MouseEvent me)
{
txt="Mouse Exited";
repaint();
}

public void mousePressed(MouseEvent me)
{
txt="Mouse Pressed";
setBackground(Color.BLUE);
setBackground(Color.GREEN);
repaint();
}


public void mouseMoved(MouseEvent me)
{

txt="Mouse Moved";
repaint();
}
public void mouseDragged(MouseEvent me)
{
txt="Mouse Dragged";
repaint();
}

public void paint(Graphics g)
{
g.drawString(txt,20,40);
}
}
/*
<applet code=Mouse1 width=400 height=400>
</applet>
*/

No comments:

Post a Comment