-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFontStyle.java
48 lines (40 loc) · 1.2 KB
/
FontStyle.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
// Input font details and output the result
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code = "FontStyle" width = "300" height = "300"> </applet> */
public class FontStyle extends Applet implements ActionListener
{
TextField t1,t2,t3;
Label l1,l2,l3;
Button b;
Font f;
public void init()
{
l1 = new Label("Font Name: ");
l2 = new Label("Font Size: ");
l3 = new Label("Font Style: "); // Input Integer in this field. 0 -> plain, 1 -> bold, 2-> italic, 3-> bold + italic
t1 = new TextField(30);
t2 = new TextField(30);
t3 = new TextField(30);
b = new Button("Show");
add(l1); add(t1);
add(l2); add(t2);
add(l3); add(t3);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String nm = t1.getText();
int sz = Integer.parseInt(t2.getText());
int st = Integer.parseInt(t3.getText());
f = new Font(nm,sz,st);
repaint();
}
public void paint(Graphics g)
{
g.setFont(f);
g.drawString("Demo String",100,200);
}
}