From e4ee7d4fd948e88b1f11f800d478853fb272bb85 Mon Sep 17 00:00:00 2001 From: mbirth Date: Wed, 8 Dec 2004 10:17:57 +0000 Subject: [PATCH] modified MyCanvas.java * Changed initial font-size to 40pt instead of 100pt - more speed * trim() text before display --- MyCanvas.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MyCanvas.java b/MyCanvas.java index bc6a6ed..43229f5 100644 --- a/MyCanvas.java +++ b/MyCanvas.java @@ -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(); } }