Java Reference
In-Depth Information
54
italicFont = new Font( "Serif" , Font.ITALIC , 14 );
55
boldItalicFont = new Font( "Serif" , Font.BOLD + Font.ITALIC , 14 );
56
textField.setFont(plainFont);
57
58
// register events for JRadioButtons
plainJRadioButton.addItemListener(
new RadioButtonHandler(plainFont));
boldJRadioButton.addItemListener(
new RadioButtonHandler(boldFont));
italicJRadioButton.addItemListener(
new RadioButtonHandler(italicFont));
boldItalicJRadioButton.addItemListener(
new RadioButtonHandler(boldItalicFont));
59
60
61
62
63
64
65
66
67
}
68
69
// private inner class to handle radio button events
70
private class RadioButtonHandler implements ItemListener
71
{
72
private Font font; // font associated with this listener
73
74
public RadioButtonHandler(Font f)
75
{
76
font = f;
77
}
78
79
// handle radio button events
80
@Override
81
public void itemStateChanged(ItemEvent event)
82
{
83
textField.setFont(font);
84
}
85
}
86
} // end class RadioButtonFrame
Fig. 12.19 | Creating radio buttons using ButtonGroup and JRadioButton . (Part 2 of 2.)
1
// Fig. 12.20: RadioButtonTest.java
2
// Testing RadioButtonFrame.
3
import javax.swing.JFrame;
4
5
public class RadioButtonTest
6
{
7
public static void main(String[] args)
8
{
9
RadioButtonFrame radioButtonFrame = new RadioButtonFrame();
10
radioButtonFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
11
radioButtonFrame.setSize( 300 , 100 );
12
radioButtonFrame.setVisible( true );
13
}
14
} // end class RadioButtonTest
Fig. 12.20 | Testing RadioButtonFrame . (Part 1 of 2.)
Search WWH ::




Custom Search