equal
deleted
inserted
replaced
|
1 /** |
|
2 * $Id: MouseListener.java 140 2008-04-25 07:03:13Z mbroeker $ |
|
3 * $URL: http://localhost/svn/eclipse/Schachspiel/trunk/org/homelinux/largo/games/board/MouseListener.java $ |
|
4 */ |
|
5 |
|
6 package org.homelinux.largo.games.board; |
|
7 |
|
8 import java.awt.event.MouseAdapter; |
|
9 import java.awt.event.MouseEvent; |
|
10 |
|
11 public class MouseListener extends MouseAdapter { |
|
12 int width; |
|
13 int height; |
|
14 int delta; |
|
15 |
|
16 Point p; |
|
17 boolean selected; |
|
18 |
|
19 public MouseListener (int w, int h) { |
|
20 width = w; |
|
21 height = h; |
|
22 p = new Point (); |
|
23 selected = false; |
|
24 } |
|
25 |
|
26 public void mousePressed (MouseEvent e) { |
|
27 p.startx = (e.getX () / width); |
|
28 p.starty = (e.getY () / height); |
|
29 selected = false; |
|
30 } |
|
31 |
|
32 public void mouseReleased (MouseEvent e) { |
|
33 p.endx = (e.getX () / width); |
|
34 p.endy = (e.getY () / height); |
|
35 |
|
36 print(); |
|
37 selected = true; |
|
38 } |
|
39 |
|
40 public boolean isSelected () { |
|
41 return selected; |
|
42 } |
|
43 |
|
44 public Point getSelection () { |
|
45 selected = false; |
|
46 return p; |
|
47 } |
|
48 |
|
49 public void print() { |
|
50 System.out.printf ("%c%d-%c%d \t", |
|
51 (char)('A' + p.startx), 8-p.starty, |
|
52 (char)('A' + p.endx), 8-p.endy); |
|
53 } |
|
54 } |