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(); } }