/* * LearnFast.java (c)1998 manifestation.com * * revised 0715.2001 - added fonts, switched to BorderLayout */ import java.applet.Applet; import java.awt.*; import java.net.URL; import java.io.*; public class LearnFast extends Applet implements Runnable { String [] messages = new String [0]; int thisMessage; Label theLabel; Thread blinkThread; boolean blinkState; int tick=1; // tracks times thread has looped Color fg; Color bg; public void init() { System.out.println("Chosen cardset = " + getParameter("cardset") ); // get the cards from a file.. try { URL url = new URL(getCodeBase(), getParameter("cardset")); System.out.println("Getting the stuff from..." + url ); BufferedReader bin = new BufferedReader ( new InputStreamReader( url.openStream ()) ); String line; // for each card: while ( (line = bin.readLine()) != null) { System.out.println("reading: " + line); // add another slot to the messages array String [] temp = new String [ messages.length + 1 ]; System.arraycopy( messages, 0, temp, 0, messages.length ); messages = temp; // and fill it with the line we read in.. messages[messages.length-1] = line; } } catch ( Exception e ) { } System.out.println("now setting up graphics stuff..."); // now set up our interface setLayout( new BorderLayout() ); theLabel = new Label(messages[0], Label.CENTER); theLabel.setFont(new Font("Monospaced", Font.BOLD, 20 )); add( theLabel ); } public void blink(){ blinkState = !blinkState; if (blinkState) { fg = Color.black; bg = Color.white; } else { fg = Color.white; bg = Color.black; } //setBackground( bg ); theLabel.setBackground( bg ); theLabel.setForeground( fg ); // every 4 times, change the text if (tick++ % 4 == 0) { if (++thisMessage >= messages.length) thisMessage = 0; theLabel.setText(messages[thisMessage]); theLabel.invalidate(); // for old VM's validate(); } repaint(); } public void run() { System.out.println("in run.."); while ( true ) { blink(); try { Thread.sleep(500); } catch (Exception e) { } } } // called whenever the applet comes on screen public void start() { System.out.println("in start().."); if ( blinkThread == null ){ blinkThread = new Thread(this); blinkThread.start(); } } // called whenever the applet goes off screen public void stop() { System.out.println("in stop().."); blinkThread = null; } }