import java.awt.*; import java.awt.event.*; import java.util.Vector; import java.io.*; public class LCDTest extends Frame implements WindowListener { public static void main(String[] args) { LCDTest test = new LCDTest(); } // -------------------------------------------------------------------------------- // Data Members // -------------------------------------------------------------------------------- private LCDTestGraphic testGraphic; private int windowWidth = 400, windowHeight = 300; private boolean loop; private Graphics graphics; private Color[] colors; private int numberOfSteps; private int rowsPerScreen; private String filename = "LCDTest.cfg"; // -------------------------------------------------------------------------------- // Constructor // -------------------------------------------------------------------------------- public LCDTest() { // call parent constructor super("LCD Test"); // set frame properties setSize(windowWidth, windowHeight); setResizable(true); Toolkit toolkit = Toolkit.getDefaultToolkit(); int xLocation = (toolkit.getScreenSize().width - windowWidth) / 2; int yLocation = (toolkit.getScreenSize().height - windowHeight) / 2; setLocation(xLocation,yLocation); setBackground(Color.black); show(); graphics = (Graphics) getGraphics(); validate(); readSettings(); reset(); // regester this frame as its own window listener addWindowListener(this); // start infinate loop run(); } // -------------------------------------------------------------------------------- // Methods // -------------------------------------------------------------------------------- public void readSettings() { try { BufferedReader br = new BufferedReader(new FileReader(new File(filename))); numberOfSteps = Integer.decode(br.readLine().substring(14)).intValue(); rowsPerScreen = Integer.decode(br.readLine().substring(14)).intValue(); String colorString = br.readLine().substring(7); Vector colorVector = new Vector(); int startIndex; int endIndex; while ((startIndex = colorString.indexOf('"')) != -1 && (endIndex = colorString.indexOf('"', startIndex + 1)) != -1) { colorVector.add(new Color(Integer.decode(colorString.substring(startIndex + 1, endIndex)).intValue())); colorString = colorString.substring(endIndex + 1); } colors = new Color[colorVector.size()]; for (int i = 0; i < colorVector.size(); i++) { colors[i] = (Color) colorVector.get(i); } } catch (Exception e) { numberOfSteps = 100; rowsPerScreen = 5; colors = new Color[] {new Color(0,0,0), new Color(64,64,64), new Color(128,128,128), new Color(191,191,191), new Color(255,255,255)}; } } public void run() { loop = true; while (loop) { if (getWidth() != windowWidth || getHeight() != windowHeight) { windowWidth = getWidth(); windowHeight = getHeight(); reset(); } graphics.drawImage(testGraphic.getImage(), 0, 0, this); } } private void reset() { testGraphic = new LCDTestGraphic(windowWidth, windowHeight, createImage(windowWidth, windowHeight), colors, numberOfSteps, rowsPerScreen); } // implementation of window listener to activate close button public void windowClosing(WindowEvent event) { loop = false; dispose(); System.exit(0); } public void windowActivated(WindowEvent event) {} public void windowClosed(WindowEvent event) {} public void windowDeactivated(WindowEvent event) {} public void windowDeiconified(WindowEvent event) {} public void windowIconified(WindowEvent event) {} public void windowOpened(WindowEvent event) {} }