-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrowingText.java
68 lines (53 loc) · 1.64 KB
/
GrowingText.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package homework3;
import java.awt.Component;
import java.awt.Font;
import javax.swing.*;
public class GrowingText extends JApplet implements Runnable {
private final JLabel lable = new JLabel("CS532-C", JLabel.CENTER);
public GrowingText() {
Component add = add(lable);
new Thread(this).start();
}
@Override
public void run() {
try {
while (true) {
if (lable.getText() == null){
Font f= lable.getFont();
lable.setText("CS532-C");
int w= f.getSize();
if(w==lable.getFont().getSize()){
lable.setFont(new Font("Arial", Font.BOLD, w+2));
int second=lable.getFont().getSize();
if(second>=52){
lable.setFont(new Font("Arial", Font.BOLD, second-42));
}
}
}
else{
lable.setText(null);
}
Thread.sleep(1000);
}
}
catch (InterruptedException w) {
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("Growing Text");
frame.add(new GrowingText());
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(350, 250);
frame.setVisible(true);
}
});
}
}