-
Notifications
You must be signed in to change notification settings - Fork 0
/
StyleGUI.java
executable file
·68 lines (56 loc) · 1.67 KB
/
StyleGUI.java
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StyleGUI
{
private final int WIDTH = 300, HEIGHT = 100, FONT_SIZE = 36;
private JLabel saying;
private JCheckBox bold, italic, underline;
private JPanel primary;
public StyleGUI()
{
saying = new JLabel ("Say it with style!");
saying.setFont (new Font ("Helvetica", Font.PLAIN, FONT_SIZE));
bold = new JCheckBox ("Bold");
bold.setBackground (Color.red);
italic = new JCheckBox ("Italic");
italic.setBackground (Color.yellow);
underline = new JCheckBox ("Underline");
underline.setBackground (Color.magenta);
StyleListener listener = new StyleListener();
bold.addItemListener (listener);
italic.addItemListener (listener);
underline.addItemListener (listener);
primary = new JPanel();
primary.add(saying);
primary.add(bold);
primary.add(italic);
primary.add(underline);
primary.setBackground (Color.orange);
primary.setPreferredSize (new Dimension (WIDTH,HEIGHT));
}
public JPanel getPanel()
{
return primary;
}
private class StyleListener implements ItemListener
{
public void itemStateChanged (ItemEvent event)
{
int style = Font.PLAIN;
if(bold.isSelected())
{
style = Font.BOLD;
}
if(italic.isSelected())
{
style += Font.ITALIC;
}
if(underline.isSelected())
{
style += Font.UNDERLINE;
}
saying.setFont (new Font ("Helvetica", style, FONT_SIZE));
}
}
}