Java Reference
In-Depth Information
13
import
javax.swing.JMenuBar;
14
import
javax.swing.JMenuItem;
15
import
javax.swing.JPanel;
16
import
javax.swing.JRadioButton;
17
import
javax.swing.border.EtchedBorder;
18
import
javax.swing.border.TitledBorder;
19
20 /**
21
This frame has a menu with commands to
change the font
22
of a text sample.
23 */
24
public class
FontViewer2Frame
extends
JFrame
25 {
26 /**
27
Constructs the frame.
28 */
29
public
FontViewer2Frame()
30 {
31 //
Construct text sample
32 sampleField =
new
JLabel(
ÐBig JavaÑ
);
33 add(sampleField, BorderLayout.CENTER);
34
35 //
Construct menu
36 JMenuBar menuBar =
new
JMenuBar();
37 setJMenuBar(menuBar);
38 menuBar.add(createFileMenu());
39 menuBar.add(createFontMenu());
40
41 facename =
ÐSerifÑ
;
42 fontsize =
24
;
43 fontstyle = Font.PLAIN;
44
45 setSampleFont();
46 setSize(FRAME_WIDTH, FRAME_HEIGHT);
47 }
48
49 /**
50
Creates the File menu.
51 @return
the menu
52 */
53
public
JMenu createFileMenu()
54 {
804
805