Uploaded by Pranot Solase

Practical 11 Output java

advertisement
Practical 11
Program Codes:
1] MouseListener:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="Practical_11" height=300 width=300>
</applet>
*/
public class Practical_11 extends Applet implements MouseListener
{
String s = "See your event here!";
public void init()
{
this.addMouseListener(this);
}
public void paint(Graphics g)
{
g.drawString(s,100,100);
}
public void mouseEntered(MouseEvent me)
{
s = "Mouse entered!";
repaint();
}
public void mouseExited(MouseEvent me)
{
s = "Mouse Exited!";
repaint();
}
public void mouseClicked(MouseEvent me)
{
s = "Mouse Clicked!";
repaint();
}
public void mousePressed(MouseEvent me)
{
s = "Mouse Pressed!";
repaint();
}
public void mouseReleased(MouseEvent me)
{
s = "Mouse Released!";
repaint();
}
}
2] MouseMotionListener:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="Practical_12" height=300 width=300>
</applet>
*/
public class Practical_12 extends Applet
{
public void init()
{
this.addMouseMotionListener(new innerl());
}
class innerl extends MouseMotionAdapter
{
public void mouseMoved(MouseEvent me)
{
int x = me.getX();
int y = me.getY();
showStatus(x + "," + y);
}
}
}
Outputs:
1] MouseListener:
2] MouseMotionListener:
Download