Oi galera, blza?
É o seguinte, preciso fazer um programinha em swing pra usar o mouse(o programa o controlaria). O programa pega como ponto de origem a posição atual, se afasta um pouco do ponto e faz um movimento contínuo. Eu definirei apenas a velocidade e a ação do mouse pela interface.
Alguem ja fez algo assim ou sabe como fazer?
Obrigado
Boa tarde…
Divirta-se com esse exemplozinho!
Ele pega teu mouse e faz uns movimentos cirulares com o ponteiro!
[code]import java.awt.Dimension;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class MouseFantasma {
public static Dimension tamanho;
public static void main(String[] args) throws Exception {
Robot robo = new Robot();
tamanho = Toolkit.getDefaultToolkit().getScreenSize();
JFrame frame = new JFrame("Fantasssssma");
JButton botao = new JButton("Mover o mouse");
frame.getContentPane().add(botao);
botao.addActionListener(new ListenerCircular(robo));
frame.pack();
frame.setLocation((int)(tamanho.getWidth() - frame.getWidth()) / 2,
(int)(tamanho.getHeight() - frame.getHeight()) / 2);
frame.show();
}
}
class ListenerCircular implements ActionListener {
Robot robot;
public ListenerCircular(Robot robot) {
this.robot = robot;
}
public void actionPerformed(ActionEvent evt) {
int xIni = (int)MouseFantasma.tamanho.getWidth() / 2;
int yIni = (int)MouseFantasma.tamanho.getHeight() / 2;
double pi = 3.1457;
for (double theta = 0; theta < 4 * pi; theta = theta + 0.1) {
double radius = theta * 20;
double x = Math.cos(theta) * radius + xIni;
double y = Math.sin(theta) * radius + yIni;
robot.mouseMove((int)x, (int)y);
try {
Thread.sleep(25);
} catch (Exception ex) {
}
}
}
}[/code]
isso é otimo para brincar de hackiar os outros…
Vlw pela ajuda e pelo exemplo
Flw, abraços