/*
 * crap.java
 *
 * Created on May 26, 2005, 11:08 PM
 */

/**
 *
 * @author  Student
 */
import java.awt.*;   // the original framework
import java.awt.event.*; // the event handler
import javax.swing.*;   // the new widgets
import java.io.*;
import java.lang.Thread;

public class crap {
    private String tosend;
    public JPanel hope;
    /** Creates a new instance of crap */
    public crap() {
    }
    
    public void doit(String data, int delay)
    {
        for(int j=0; j<8; j++)
            if (data.charAt(j) == '1') 
            {hope.setBackground(Color.WHITE);
            try{Thread.sleep((int)delay);}catch (InterruptedException e){}    
            }
            else 
            {hope.setBackground(Color.BLACK);
            try{Thread.sleep((int)delay);}catch (InterruptedException e){}    
            }
       hope.validate();
       //try{Thread.sleep((int)delay);}catch (InterruptedException e){}    
        }
    
    public void ihatejava(String filename, String delay)
    {
        int intdelay = Integer.parseInt(delay);
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();
        GraphicsDevice currentDevice = devices[0];
        JFrame frame = new JFrame();
        hope = new JPanel();
        frame.getContentPane().add( hope );
        frame.setUndecorated( true );
        frame.setResizable( false );
        currentDevice.setFullScreenWindow( frame );
        
        tosend = new String();
        FileInputStream fis;
        DataInputStream dis;
        try {
      fis = new FileInputStream(filename);
      
      //output stream
      FileOutputStream fos;
      DataOutputStream ds;
      fos = new FileOutputStream("output.pdf");
      ds = new DataOutputStream( fos );
      // Wrap with a DataInputStream to obtain
      // its readInt() method.
      dis = new DataInputStream( fis );
      //System.out.println( "file: " + filename );

      int i;

      while ( true ) {
                   //i = dis.readInt();
         i = dis.readUnsignedByte();
         tosend = leftPad(Integer.toBinaryString(i),8,'0');
         //System.out.print(tosend + "|");
         //i = dis.readInt();
         doit(tosend, intdelay);
         //System.out.print(tosend + "|");
         //ds.writeByte((byte)i); //uncomment this to write the output file
      }
    } catch (EOFException eof)  
      {System.out.println( "Done " ); }
      catch (IOException ioe) 
      {System.out.println( "IO error: " + ioe );}   
        System.exit(0);
        //currentDevice.setDisplayMode( dm );
    }
    /**
     * @param args the command line arguments
     */
public String leftPad(String s, int length, char pad) {
        StringBuffer buffer = new StringBuffer(s);
        while (buffer.length() < length) {
	buffer.append(pad);
    }
return buffer.toString();
}
    public static void main(String[] args) {
       crap mything = new crap();
       mything.ihatejava(args[0], args[1]);
    }
    
}
