import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class TestaInputMouse{
private JFrame f=new JFrame("mouse input");
private Pannello p=new Pannello();
int clickx;
int clicky;
int clickxP;
int clickyP;
int clickxR;
int clickyR;
public TestaInputMouse(){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500,500);
f.add(p);
f.setVisible(true);
f.addMouseListener(new Mouse());
f.setVisible(true);
}
public class Pannello extends JPanel{
public void paintComponent(Graphics g){
String tizio="mouse cliccato "+clickx+", "+clicky;
g.drawString(tizio,10,20);
tizio="mouse premuto a cord. "+clickxP+", "+clickyP;
g.drawString(tizio,10,40);
tizio="mouse premuto rilsciato "+clickxR+", "+clickyR;
g.drawString(tizio,10,60);
g.fillRect(clickx,clicky,10,20);
}
}
public static void main(String[] args){
TestaInputMouse t=new TestaInputMouse();
}
public class Mouse implements MouseListener{
public void mousePressed(MouseEvent e){
clickxP=e.getX()-5;
clickyP=e.getY()-24;
f.repaint();
}
public void mouseReleased(MouseEvent e){
clickxR=e.getX()-5;
clickyR=e.getY()-24;
f.repaint();
}
public void mouseClicked(MouseEvent e){
clickx=e.getX()-5;
clicky=e.getY()-24;
f.repaint();
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
}
}
_____________________________________________________________________________
Quickpost this image to Myspace, Digg, Facebook, and others!
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento