// Parallel Computing // // Display applet // // Author Matthew Caryl // Created 2.2.97 package Parallel; import java.awt.Graphics; import java.awt.Color; import java.awt.Event; import java.applet.Applet; import java.lang.System; import java.io.*; public final class Display extends Applet implements Viewer { // // Private interface // public static final Color backgroundColor = Color.black; public static final Color outlineColor = Color.white; private Graphics graphics; private Computer computer; // // Public interface // public void init() { setBackground(backgroundColor); graphics = this.getGraphics(); Computer.registerComputer(this, getParameter("computerName"), 0, 0); } public void destroy() { stop(); if (graphics != null) graphics.dispose(); } public void paint(Graphics g) { g.setColor(backgroundColor); g.fillRect(0, 0, size().width, size().height); g.setColor(outlineColor); if (computer != null) { String message = new String("Computer is present"); int messageWidth = graphics.getFontMetrics(graphics.getFont()).stringWidth(message); int messageHeight = graphics.getFontMetrics(graphics.getFont()).getHeight(); g.drawString(message, size().width / 2 - messageWidth / 2, size().height / 2 + messageHeight / 2); } else { String message = new String("Computer is not present"); int messageWidth = graphics.getFontMetrics(graphics.getFont()).stringWidth(message); int messageHeight = graphics.getFontMetrics(graphics.getFont()).getHeight(); g.drawString(message, size().width / 2 - messageWidth / 2, size().height / 2 + messageHeight / 2); } } public String[][] getParameterInfo() { String[][] info = {{"computerName", "string", "name of computer to access"}}; return info; } public void setComputer(Computer C) { System.out.println("set display"); computer = C; update(graphics); } }