Tuesday, 12 May 2015

Applet programming : Implementing mouse Listeners

Exported from Notepad++
import java.awt.*; import java.awt.event.*; import java.applet.*; public class MouseA extends Applet implements MouseListener { //here MouseListener interface is implemented String msg="MouseEvents"; static int x=1; public void init() { //below code makes the applet to take information from mouse events addMouseListener(this); setBackground(Color.white); setForeground(Color.blue); } public void mouseEntered(MouseEvent m) { showStatus("Mouse Entered"); msg="Mouse Entered"; //Repaint invokes the paint method repaint(); } public void mouseExited(MouseEvent m) { showStatus("Mouse Exited"); msg="Mouse Exited"; repaint(); } public void mousePressed(MouseEvent m) { showStatus("Mouse Pressed"); msg="Mouse Pressed"; repaint(); } public void mouseReleased(MouseEvent m) { showStatus("Mouse Released"); msg="Mouse Released"; repaint(); //showStatus shows the string in it at below of applet } public void paint(Graphics g) { x+=1; g.drawString(msg+"\n",x,x); } public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub showStatus("Mouse Clicked"); msg="Mouse Clicked"; repaint(); } }


No comments:

Post a Comment