0
|
1
|
|
2
|
|
3 package trefle;
|
|
4
|
|
5 import java.awt.Canvas;
|
|
6 import java.awt.Graphics;
|
|
7 import javax.swing.JFrame;
|
|
8 import java.awt.event.MouseListener;
|
|
9 import java.awt.event.MouseEvent;
|
|
10
|
|
11
|
|
12 public class Mouse implements MouseListener {
|
|
13 int x,y,px,py;
|
|
14 int tw,th;
|
|
15 Trefle trefle;
|
|
16 boolean click = false;
|
|
17
|
|
18
|
|
19 @Override
|
|
20 public void mousePressed(MouseEvent e){
|
|
21 System.out.println("Mysz nacisnieta - liczba klikiniec:"+e.getClickCount()+" wspolrzedne x: "+e.getX()+" y: "+e.getY());
|
|
22 x=e.getX();
|
|
23 y=e.getY();
|
|
24 click=true;
|
|
25 //trefle.repaint();
|
|
26 }
|
|
27 @Override
|
|
28 public void mouseReleased(MouseEvent e){
|
|
29 System.out.println("Mysz zwolniona - liczba klikiniec:"+e.getClickCount()+" wspolrzedne x: "+e.getX()+" y: "+e.getY());
|
|
30 px=e.getX();
|
|
31 py=e.getY();
|
|
32 click=false;
|
|
33 //trefle.repaint();
|
|
34 }
|
|
35 @Override
|
|
36 public void mouseEntered(MouseEvent e){
|
|
37 System.out.println("Wprowadzono mysz");
|
|
38 x=e.getX();
|
|
39 y=e.getY();
|
|
40 px=e.getX();
|
|
41 py=e.getY();
|
|
42 }
|
|
43 @Override
|
|
44 public void mouseExited(MouseEvent e){
|
|
45 System.out.println("Mysz wyszla:");
|
|
46 }
|
|
47 @Override
|
|
48 public void mouseClicked(MouseEvent e){
|
|
49 System.out.println("Kliknieto mysza - liczba klikniec:"+e.getClickCount());
|
|
50 System.out.println("Klikinito klawiszem:"+e.getButton());
|
|
51 click=true;
|
|
52 //trefle.repaint();
|
|
53 }
|
|
54 public Coordinate getCell(){
|
|
55 Coordinate cor = new Coordinate(x,y,click); //return y*4+x;
|
|
56 return cor;
|
|
57 }
|
|
58 public Coordinate putCell() {
|
|
59 Coordinate cor = new Coordinate(px,py,click); //return py*4+px;
|
|
60 return cor;
|
|
61 }
|
|
62 public void set (int _tw, int _th){
|
|
63 tw=_tw;
|
|
64 th=_th;
|
|
65 }
|
|
66 public void setCanvas(Trefle t){
|
|
67 trefle = t;
|
|
68 }
|
|
69 }
|