-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFonts.java
More file actions
136 lines (93 loc) · 3.61 KB
/
Copy pathFonts.java
File metadata and controls
136 lines (93 loc) · 3.61 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*A class for creating JFontDialog
*/
public class Fonts extends JDialog {
private static final long serialVersionUID = 1L;
/**
*@see Center.java
*this class to make the JDialog in the center
*/
public Center center = new Center(this);
//declaration of the private variables used in the program
private JPanel jp = new JPanel();
private JLabel fjl = new JLabel("Fonts: ");
private JComboBox fjcb = new JComboBox();
/**
*-> GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames() <-
* WE USING THIS METHOD TO GET ALL FONT IN THE SYSTEM (OS)
*/
private String fonts[]=GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
private JLabel sjl = new JLabel("Sizes: ");
private JComboBox sjcb = new JComboBox();
private String sizes[] = {"8","10","12","14","16","18","20","24","28","32","48","72"};
private JLabel tjl = new JLabel("Types: ");
private JComboBox tjcb = new JComboBox();
private String types[] = {"Regular", "Bold", "Italic", "Bold Italic"};
private JLabel jjl = new JLabel("Preview:");
private JLabel jl = new JLabel("AaBaCcDdeEfFgGhHjJ");
private JButton okjb = new JButton("OK");
private JButton cajb = new JButton("Cancel");
//for using ok & cancel button @Actions.java
public JButton getOkjb(){
return okjb;
}
public JButton getCajb(){
return cajb;
}
//Constructor of Fonts
public Fonts(){
//for setting the title
setTitle("Font Dialog");
setResizable(false);
/**
*setting the layout (GridLayout: 5 rows & 2 columns)
*add font JLabel, add font JComboBox
*add type JLabel, add type JComboBox
*add size JLabel, add size JComboBox
*add preview JLabel,add test JLabel
*add ok button, add cancel button
*/
jp.setLayout(new GridLayout(5,2,1,1));
jp.add(fjl);
jp.add(fjcb = new JComboBox(fonts));
jp.add(sjl);
jp.add(sjcb = new JComboBox(sizes));
jp.add(tjl);
jp.add(tjcb = new JComboBox(types));
jp.add(jjl);
jl.setBorder(BorderFactory.createEtchedBorder());
jp.add(jl);
jp.add(okjb);
jp.add(cajb);
//add JPanel to the Container
this.getContentPane().add(jp);
/**
*for making JDialog at the center,
*@Center.java
*/
center.fCenter();
//add action listener to Font JComboBox to get the selected item for setting the preview
fjcb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
jl.setFont(new Font(String.valueOf(fjcb.getSelectedItem()),tjcb.getSelectedIndex(),14));
}
});
//add action listener to Type JComboBox to get the selected index for setting the preview
tjcb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
jl.setFont(new Font(String.valueOf(fjcb.getSelectedItem()),tjcb.getSelectedIndex(),14));
}
});
}
/*
*@return font value: (Font,Type,Size)
*/
public Font font(){
Font font = new Font(String.valueOf(fjcb.getSelectedItem()), tjcb.getSelectedIndex(),
Integer.parseInt(String.valueOf(sjcb.getSelectedItem())));
return font;
}
}