1 36 37 40 41 import java.awt.Graphics ; 42 43 52 class ClickArea extends ImageMapArea { 53 54 int startx; 55 56 int starty; 57 58 boolean dragging; 59 60 static String ptstr(int x, int y) { 61 return "("+x+", "+y+")"; 62 } 63 64 68 public boolean press(int x, int y) { 69 showStatus("Clicked at "+ptstr(x, y)); 70 startx = x; 71 starty = y; 72 dragging = true; 73 return false; 74 } 75 76 80 public boolean drag(int x, int y) { 81 showStatus("Rectangle from "+ptstr(startx, starty) 82 +" to "+ptstr(x, y) 83 +" is "+(x-startx)+"x"+(y-starty)); 84 return false; 85 } 86 87 91 public boolean lift(int x, int y) { 92 dragging = false; 93 return drag(x, y); 94 } 95 96 103 public String getStatus(String prevmsg) { 104 if (dragging) { 105 return (status != null) ? status : prevmsg; 106 } else { 107 return (prevmsg == null) ? status : prevmsg; 108 } 109 } 110 } 111 112 | Popular Tags |