Program for handling mouse events.
Program:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="mouse.class" height=800 width=800>
</applet>*/
public class mouse extends Applet implements MouseListener,MouseMotionListener
{
String msg;
int mousex=0,mousey=0;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent m)
{
mousex=0;
mousey=0;
msg="mouse clicked";
repaint();
}
public void mouseReleased(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="up";
repaint();
}
public void mouseEntered(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse entered";
repaint();
}
public void mouseExited(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse exited";
repaint();
}
public void mousePressed(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse pressed";
repaint();
}
public void mouseDragged(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse dragged";
repaint();
}
public void mouseMoved(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
showStatus("moving at:"+mousex+","+mousey);
}
public void paint(Graphics g)
{
g.drawString(msg,mousex,mousey);
}
}
import java.awt.event.*;
import java.applet.*;
/*<applet code="mouse.class" height=800 width=800>
</applet>*/
public class mouse extends Applet implements MouseListener,MouseMotionListener
{
String msg;
int mousex=0,mousey=0;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent m)
{
mousex=0;
mousey=0;
msg="mouse clicked";
repaint();
}
public void mouseReleased(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="up";
repaint();
}
public void mouseEntered(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse entered";
repaint();
}
public void mouseExited(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse exited";
repaint();
}
public void mousePressed(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse pressed";
repaint();
}
public void mouseDragged(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
msg="mouse dragged";
repaint();
}
public void mouseMoved(MouseEvent m)
{
mousex=m.getX();
mousey=m.getY();
showStatus("moving at:"+mousex+","+mousey);
}
public void paint(Graphics g)
{
g.drawString(msg,mousex,mousey);
}
}
Execution process:-
1- develop the applet code(.java)
2-compile the applet code(.class)
3-write the basic HTML structure format
4-develop the APPLET tag for the applet
5-insert the APPLET tag in HTML code
6-run it using appletviewer (appletviewer ______.htmlfile) or
double clicking on (.htmlfile) you created.
1- develop the applet code(.java)
2-compile the applet code(.class)
3-write the basic HTML structure format
4-develop the APPLET tag for the applet
5-insert the APPLET tag in HTML code
6-run it using appletviewer (appletviewer ______.htmlfile) or
double clicking on (.htmlfile) you created.
nice post thanks
ReplyDeleteDDA Recruitment 2015: Are you looking for Assistant Engineer Jobs at Delhi Development Authority? Then your wait is over because DDA has released its notification for the AE Jobs
thank you posting Latest Govt Jobs
ReplyDeletethank you posting Latest Govt Jobs
ReplyDelete