modified MyCanvas.java
* Changed initial font-size to 40pt instead of 100pt - more speed * trim() text before display
This commit is contained in:
parent
cea6530d2d
commit
e4ee7d4fd9
@ -9,7 +9,7 @@ class MyCanvas extends Canvas {
|
||||
Color bgColor = new Color(0,0,128);
|
||||
Color fgColor = new Color(255,255,0);
|
||||
String word = "";
|
||||
int maxFontSize = 100;
|
||||
int maxFontSize = 40;
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(bgColor);
|
||||
@ -25,15 +25,16 @@ class MyCanvas extends Canvas {
|
||||
do {
|
||||
f = new Font("Dialog", Font.BOLD, fs);
|
||||
fm = g.getFontMetrics(f);
|
||||
fs -= 2;
|
||||
} while ((fm.stringWidth(word)>getSize().width-2) || (fm.getHeight()>getSize().height-2));
|
||||
// System.out.println("MyC: Font-size now "+fs+"pt.");
|
||||
fs -= 4;
|
||||
} while (((fm.stringWidth(word)>getSize().width-2) || (fm.getHeight()>getSize().height-2)) && fs > 0);
|
||||
g.setFont(f);
|
||||
g.drawString(word, getSize().width/2-fm.stringWidth(word)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||
}
|
||||
}
|
||||
|
||||
public void setWord(String txt) {
|
||||
word = txt;
|
||||
word = txt.trim();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user