// tinyptc.java import java.applet.Applet; import java.awt.*; import java.awt.image.*; public abstract class tinyptc extends Applet implements Runnable, ImageProducer { public tinyptc () {} public synchronized void addConsumer (ImageConsumer imageconsumer) { _consm = imageconsumer; _consm.setDimensions (_w, _h); _consm.setHints (30); _consm.setColorModel (_dcm); } public synchronized boolean isConsumer (ImageConsumer imageconsumer) { return false; } public synchronized void removeConsumer (ImageConsumer imageconsumer) {} public void requestTopDownLeftRightResend (ImageConsumer imageconsumer) {} public void startProduction (ImageConsumer imageconsumer) { addConsumer (imageconsumer); } public abstract void main (int i, int j); public void run () { Dimension dim = size (); _w = dim.width; _h = dim.height; _dcm = new DirectColorModel (32, 0xff0000, 65280, 255, 0); _img = createImage (this); main (_w, _h); } public void start () { if (_thr == null) {_thr = new Thread (this); _thr.start ();} } public void stop () { if (_thr != null && _thr.isAlive ()) _thr.stop (); _thr = null; } protected synchronized void paint () { Graphics g = getGraphics (); if (_img != null && g != null) g.drawImage (_img, 0, 0, _w, _h, null); } public synchronized void update (int ai[]) { if (_consm != null) { _consm.setPixels (0, 0, _w, _h, _dcm, ai, 0, _w); _consm.imageComplete (2); } paint (); } int _w, _h; Thread _thr; Image _img; DirectColorModel _dcm; ImageConsumer _consm; }