FileDocCategorySizeDatePackage
fits.javaAPI DocExample1424Thu Apr 03 15:27:46 BST 1997None

fits.java

import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.io.*;

public class fits extends Frame implements ContentHandlerFactory {

  URL u;
  Image theImage;
  String name;
  ContentHandler fc;

  public static void main(String[] args) {
  
    String name;
    if (args.length == 0) name = "test.fit";
    else name = args[0] + ".fits";
  
    fits f = new fits(name);
    URLConnection.setContentHandlerFactory(f);
    f.resize(252, 252);
    f.fc = new fitsContentHandler();
    f.init();
    f.show();
  
  }
  
  public ContentHandler createContentHandler(String mimetype) {
  
    if (mimetype.equalsIgnoreCase("image/x-fits")) return fc;
    return null;
  
  }
  
  public fits(String s) {
  
    super(s);
    name = s;
  
  }
  
  public void init() {
  
    try {
    
      u = new URL("http://sunsite.unc.edu/javafaq/" + name);            
      
      ImageProducer ip = (ImageProducer) u.getContent();
      if (ip == null)  {
        System.err.println("Content handler returned null");
      }
      else {
       theImage = createImage(ip);
      }

    }
    catch (MalformedURLException e) {
      System.err.println(e);
    }
    catch (IOException e) {
      System.err.println(e);
    }
    catch (NullPointerException e) {
      System.err.println(e);
      e.printStackTrace();
    }
    
  }
  
public void paint(Graphics g) {
  
    g.drawImage(theImage, 0, 0, this);
  
  }

}