// Processed by NMI's Java Code Viewer 4.8.2 © 1997-2000 B. Lemaire // Website: http://njcv.htmlplanet.com E-mail: info@njcv.htmlplanet.com // Copy registered to Evaluation Copy // Source File Name: PlayerName.java import java.awt.*; class PlayerName extends Canvas { String name; private Font font; private FontMetrics metrics; private boolean myturn; private Timer timer; private Image arrow; private byte counter; private boolean left; private Image offImage; private Graphics offGraphics; public PlayerName(String s, Image image) { font = new Font("TimesRoman", 1, 16); myturn = false; left = false; name = s; arrow = image; metrics = getFontMetrics(font); resize(metrics.stringWidth(s) + 4 + 30, metrics.getHeight() + 4); timer = new Timer(this, 65, true, 1001, 2); } public void setText(String s) { name = s; resize(metrics.stringWidth(s) + 4 + 30, metrics.getHeight() + 4); repaint(); } public String getText() { return name; } public boolean getMyTurn() { return myturn; } public void turn(boolean flag) { myturn = flag; if(flag) { timer = new Timer(this, 65, true, 1001, 2); timer.start(); } else { timer.stop(); } repaint(); } public void paint(Graphics g) { update(g); } public void update(Graphics g) { if(offGraphics == null) { offImage = createImage(30, size().height); offGraphics = offImage.getGraphics(); offGraphics.drawImage(arrow, counter, 6, this); return; } g.setFont(font); if(myturn) { g.setColor(Color.red); try { g.drawString(name.substring(0, 8), 30, 17); } catch(StringIndexOutOfBoundsException _ex) { g.drawString(name, 30, 17); } g.drawImage(offImage, 0, 0, this); offGraphics.clearRect(0, 0, 30, size().height); offGraphics.drawImage(arrow, counter, 5, this); return; } g.clearRect(0, 0, 30, size().height); g.setColor(Color.black); try { g.drawString(name.substring(0, 8), 30, 17); return; } catch(StringIndexOutOfBoundsException _ex) { g.drawString(name, 30, 17); } } public boolean handleEvent(Event event) { if(event.target == timer && event.id == 1001) { if(!left) counter++; else counter--; if(counter == 7) left = true; if(counter == 0) left = false; repaint(0, 0, 30, size().height); return true; } else { return false; } } }