/** begin displaying the message */ public void begin() { g2d.clearAll = false; g2d.paintAll = false; super.start(); }
/** end displaying message and force a graph repaint */ public void end() { super.stop(); g2d.clearAll = true; g2d.paintAll = true; if (lg != null) lg.dispose(); g2d.repaint(); }
/** The method to call when the thread starts */ public void run() { boolean draw = true; FontMetrics fm; Rectangle r; int sw = 0; int sa = 0; int x = 0; int y = 0; setPriority(Thread.MIN_PRIORITY); while (true) { if (newmessage != null && draw) { message = newmessage; newmessage = null; } if (lg == null) { lg = g2d.getGraphics(); if (lg != null) lg = lg.create(); } if (lg != null) { if (f != null) lg.setFont(f); fm = lg.getFontMetrics(lg.getFont()); sw = fm.stringWidth(message); sa = fm.getAscent(); } else { draw = false; } if (draw) { lg.setColor(foreground); r = g2d.bounds(); x = r.x + (r.width - sw) / 2; y = r.y + (r.height + sa) / 2; lg.drawString(message, x, y); g2d.repaint(); try { sleep(visible); } catch (Exception e) { } } else { if (lg != null) { lg.setColor(g2d.getBackground()); lg.drawString(message, x, y); g2d.repaint(); } try { sleep(invisible); } catch (Exception e) { } } draw = !draw; } }