deber curva eventos raton teclado
TRANSCRIPT
![Page 1: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/1.jpg)
1/1/2011
DISEÑAR UN APPLET, QUE MUESTRE EN PANTALLA CUALQUIER CURVA MATEMATICA, CONSULTAR LOS EVENTOS DE TECLADO Y RATON EN JAVA
FERNANDO
BELTRÁN
FUENTES PROGRAMACION AVANZADA
![Page 2: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/2.jpg)
1.- DISEÑAR UN APPLET, QUE MUESTRE EN PANTALLA CUALQUIER
CURVA MATEMATICA. CURVA DE LA COTANGENTE
import java.applet.Applet;
import java.awt.*;
public class curvadistribucion extends java.applet.Applet {
public double funcion (double x)
{
return (Math. tanh (x/25)+2)*getSize().height/4;
}
public void init() {
// TODO start asynchronous download of heavy resources
}
public void paint(Graphics g) {
for (int i=0;i<=700;i++)
g.drawLine(i,(int)funcion(i),i+1,(int)funcion(i+1));
}
}
![Page 3: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/3.jpg)
Curva Cotangente
2.- CONSULTAR LOS EVENTOS DEL RATON Y DEL TECLADO EN JAVA
Java – Clase java.awt.Robot – Control de mouse, teclado, y captura
de pantalla Para poder tener control sobre el mouse y el teclado del PC a través de la API estándar de Java
haremos uso de la clase Robot, a continuación veremos de que trata esta clase y sus posibilidades:
![Page 4: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/4.jpg)
Clase java.awt.Robot
Esta clase, ubicada en el paquete java.awt, la tenemos disponible desde la versión J2SE 1.3 y fue
diseñada con el propósito de la automatización de pruebas y cualquier actividad que involucre el
mouse o teclado sin la presencia o interacción física del usuario. Con esta clase se pueden generar
auténticos eventos de entrada nativos del sistema pudiendo emular casi toda acción del usuario.
Hay que destacar que algunos sistemas operativos podrían restringir el acceso a estos eventos de
entrada, en tal caso una AWTException seria arrojada al tratar de construir un objeto de esta
clase.
- Control del mouse - Hay muchas cosas que podemos hacer con el mouse, veamos:
Mover el puntero de posición:
01 import java.awt.Robot;
02 import java.awt.AWTException;
03
04 class ControlMouse1 {
05
06 public static void main(String[] args) throws AWTException; {
07 //instanciamos la clase Robot
08 Robot robot = new Robot();
09
![Page 5: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/5.jpg)
10 //cambia la posición en pantalla del puntero a las
coordenadas
11 //X=300 e Y=600.
12 robot.mouseMove(300, 600);
13 }
14 }
Click con el botón derecho:
01 import java.awt.Robot;
02 import java.awt.AWTException;
03 import java.awt.event.InputEvent;
04
05 class ControlMouse2 {
06
07 public static void main(String[] args) throws AWTException {
08 //instanciamos la clase Robot
09 Robot robot = new Robot();
10
![Page 6: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/6.jpg)
11 //click con el boton derecho
12 robot.mousePress(InputEvent.BUTTON3_MASK);
13 robot.mouseRelease(InputEvent.BUTTON3_MASK);
14 }
15 }
Click con el botón izquierdo:
01 import java.awt.Robot;
02 import java.awt.AWTException;
03 import java.awt.event.InputEvent;
04
05 class ControlMouse3 {
06
07 public static void main(String[] args) throws AWTException {
08 //instanciamos la clase Robot
09 Robot robot = new Robot();
10
![Page 7: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/7.jpg)
11 //click con el boton izquierdo
12 robot.mousePress(InputEvent.BUTTON1_MASK);
13 robot.mouseRelease(InputEvent.BUTTON1_MASK);
14 }
15 }
Click con la rueda del mouse:
01 import java.awt.Robot;
02 import java.awt.AWTException;
03 import java.awt.event.InputEvent;
04
05 class ControlMouse4 {
06
07 public static void main(String[] args) throws AWTException {
08 //instanciamos la clase Robot
09 Robot robot = new Robot();
10
![Page 8: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/8.jpg)
11 //click con la rueda del mouse
12 robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
13 robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
14 }
15 }
Desplazar la rueda del mouse:
01 import java.awt.Robot;
02 import java.awt.AWTException;
03 import java.awt.event.InputEvent;
04
05 class ControlMouse5 {
06
07 public static void main(String[] args) throws AWTException {
08 //instanciamos la clase Robot
09 Robot robot = new Robot();
10
![Page 9: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/9.jpg)
11 //desplazar la rueda del mouse
12 robot.mouseWheel(-100);
13 }
14 }
- Control del teclado -
Podremos presionar y soltar teclas de nuestro teclado, veamos
algunos ejemplos:
Presionar/soltar una tecla:
01 import java.awt.Robot;
02 import java.awt.AWTException;
03 import java.awt.event.InputEvent;
04
05 class ControlTeclado1 {
06
07 public static void main(String[] args) throws AWTException {
08 //instanciamos un robot
![Page 10: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/10.jpg)
09 Robot robot = new Robot();
10
11 //abrir el menu inicio en windows
12 robot.keyPress(KeyEvent.VK_WINDOWS);
13 robot.keyRelease(KeyEvent.VK_WINDOWS);
14 }
15 }
Escribiendo un texto en la ventana activa:
01 import java.awt.Robot;
02 import java.awt.AWTException;
03 import java.awt.event.KeyEvent;
04
05 class ControlTeclado2 {
06
07 //arreglo de teclas para escribir "HOLA MUNDO" en la ventana
activa del escritorio
08 final static int teclas[] = {
![Page 11: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/11.jpg)
09 KeyEvent.VK_H, KeyEvent.VK_O,
10 KeyEvent.VK_L, KeyEvent.VK_A,
11 KeyEvent.VK_SPACE, KeyEvent.VK_M,
12 KeyEvent.VK_U, KeyEvent.VK_N,
13 KeyEvent.VK_D, KeyEvent.VK_O
14 };
15
16 public static void main(String[] args) throws AWTException {
17 //instanciamos la clase Robot
18 Robot robot = new Robot();
19
20 //esperamos 2 segundos antes de empesar a escribir
21 robot.delay(2000);
22
23 //iteramos a través del array de teclas
24 for (int i = 0 ; i < teclas.length ; i++) {
![Page 12: Deber Curva Eventos Raton Teclado](https://reader033.vdocuments.net/reader033/viewer/2022050920/54fdb0514a7959ba458b4eec/html5/thumbnails/12.jpg)
25 //presionamos y soltamos cada tecla del array
26 robot.keyPress(teclas[i]);
27 robot.keyRelease(teclas[i]);
28
29 //dormimos el robot por 250 milisegundos luego de usar
cada tecla
30 robot.delay(250);
31 }
32 }
33