Created
February 10, 2017 15:09
-
-
Save LuisFcoOrtiz/68fb3ffcc2872cc4ca064944633a6b48 to your computer and use it in GitHub Desktop.
Panel que registra los eventos del raton MouseListener JAVA | Panel for watch the mouse events MouseListener JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* EventosRaton.java | |
* | |
* Copyright 2017 manrique <https:/github.com/luisFcoOrtiz> | |
* | |
*/ | |
import java.awt.*; | |
import java.awt.event.*; | |
public class EventosRaton extends Frame { | |
TextArea textArea1; | |
public EventosRaton(String titulo) { | |
super(titulo); | |
setLayout(new GridLayout(2,1)); | |
Panel panel1 = new Panel(); | |
panel1.setBackground(new Color(0,255,0)); | |
add(panel1); | |
textArea1 = new TextArea("",5,20,TextArea.SCROLLBARS_BOTH); | |
textArea1.setEditable(false); | |
add(textArea1); | |
addWindowListener(new ControlVentana()); | |
panel1.addMouseListener(new ControlRaton()); | |
panel1.addMouseMotionListener(new ControlRaton()); | |
} | |
//cierra la ventana | |
class ControlVentana extends WindowAdapter { | |
public void windowClosing(WindowEvent e) { | |
System.exit(0); | |
} | |
}//Fin Cerrar ventana | |
//Controla el raton | |
class ControlRaton implements MouseListener, MouseMotionListener{ | |
//Metodos de MouseListener | |
public void mouseEntered(MouseEvent m) { | |
textArea1.append("Raton ha entrado en el area\n"); | |
} | |
public void mouseExited(MouseEvent m) { | |
textArea1.append("Raton ha salido en el area\n"); | |
} | |
public void mouseReleased(MouseEvent m) { | |
textArea1.append("Boton soltado\n"); | |
} | |
public void mousePressed(MouseEvent m) { | |
textArea1.append("Boton pulsado\n"); | |
} | |
public void mouseClicked(MouseEvent m) { | |
if(m.getButton()==MouseEvent.BUTTON1) { | |
textArea1.append("Clickado el boton izquierdo\n"); | |
} else if (m.getButton()==MouseEvent.BUTTON2) { | |
textArea1.append("Clickado el boton derecho\n"); | |
}else if (m.getButton()==MouseEvent.BUTTON3) { | |
textArea1.append("Ruleta de raton presionada\n"); | |
} | |
} | |
//Metodos de MouseMotionListener | |
public void mouseMoved(MouseEvent m) { | |
textArea1.append( "coordenadas=> X: " + m.getX() + "Y: " + m.getY() + "\n" ); | |
} | |
public void mouseDragged (MouseEvent m) {} | |
}//Fin controlRaton | |
}//Fin clase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment