-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustombutton.java
More file actions
66 lines (46 loc) · 1.43 KB
/
custombutton.java
File metadata and controls
66 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
This class implements a simple button with an
image (you can change in runtime) on it.
*/
import java.awt.*;
class custombutton extends Canvas {
Container pappy;
Image image;
Dimension minSize;
int w, h;
int DOWN=1,UP=0;
int buttonstatus=UP;
public custombutton(Image image, Container parent, int initialWidth, int initialHeight) {
this.image = image;
pappy = parent;
w = initialWidth;
h = initialHeight;
minSize = new Dimension(w,h);
}
public Dimension preferredSize() { return minSize; /* minimumSize();*/ }
public synchronized Dimension minimumSize() { return minSize; }
public void setImage(Image img){
this.image=img;
repaint();
}
public boolean mouseDown(Event evt,int x,int y){
buttonstatus=DOWN;
repaint();
return true;
}
public boolean mouseUp(Event evt,int x,int y){
buttonstatus=UP;
repaint();
return false;
}
public void paint (Graphics g) {
if (buttonstatus==UP) {
g.setColor(getBackground());
g.draw3DRect(0,0,size().width-2,size().height-2,true);
} else {
g.setColor(getBackground());
g.fillRect(1,1,size().width,size().height);
}
if (image!=null) g.drawImage(image, (size().width-image.getWidth(this))/2, (size().height-image.getHeight(this))/2, this);
}
} // end class