-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFaces.java
More file actions
81 lines (67 loc) · 2.17 KB
/
Faces.java
File metadata and controls
81 lines (67 loc) · 2.17 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package gui;
/**
* RUN:
* javac -cp .; gui/Faces.java && java -cp .; gui.Faces
* OUTPUT:
*
*/
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import net.mindview.util.*;
public class Faces extends JFrame {
private static final int WIDTH = 250;
private static final int HEIHGT = 125;
private static Icon[] faces;
private JButton jb;
private JButton jb2 = new JButton("Disable");
private boolean mad = false;
public Faces() {
faces = new Icon[] {
new ImageIcon(getClass().getResource("Face0.gif")),
new ImageIcon(getClass().getResource("Face1.gif")),
new ImageIcon(getClass().getResource("Face2.gif")),
new ImageIcon(getClass().getResource("Face3.gif")),
new ImageIcon(getClass().getResource("Face4.gif")),
};
jb = new JButton("JButton", faces[3]);
setLayout(new FlowLayout());
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (mad) {
jb.setIcon(faces[3]);
mad = false;
}
else {
jb.setIcon(faces[0]);
mad = true;
}
jb.setVerticalAlignment(JButton.TOP);
jb.setHorizontalAlignment(JButton.LEFT);
}
});
jb.setRolloverEnabled(true);
jb.setRolloverIcon(faces[1]);
jb.setPressedIcon(faces[2]);
jb.setDisabledIcon(faces[4]);
jb.setToolTipText("Yow!");
add(jb);
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (jb.isEnabled()) {
jb.setEnabled(false);
jb2.setText("Enabled");
}
else {
jb.setEnabled(true);
jb2.setText("Disabled");
}
}
});
add(jb2);
}
public static void main(String[] args) {
SwingConsole.run(new Faces(), WIDTH, HEIHGT);
}
}