-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathText.java
42 lines (34 loc) · 878 Bytes
/
Text.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
import java.awt.*;
public class Text{
//field
private double x;
private double y;
private long time;
private String s;
private long start;
//constructor
public Text(double x,double y,long time,String s){
this.x=x;
this.y=y;
this.time=time;
this.s=s;
start=System.nanoTime();
}
public boolean update()
{
long elapsed=(System.nanoTime()-start)/1000000;
if(elapsed>time){
return true;
}
return false;
}
public void draw(Graphics2D g){
g.setFont(new Font("Century Gothic",Font.PLAIN,18));
long elapsed=(System.nanoTime()-start)/1000000;
int alpha=(int)(255*Math.sin(3.14*elapsed/time));
if(alpha>255||alpha<0)alpha=255;
g.setColor(new Color(255,255,255,alpha));
int length=(int)g.getFontMetrics().getStringBounds(s,g).getWidth();
g.drawString(s,(int)(x-(length/2)),(int)y);
}
}