Package scanner provides abstract parent classes to the classes in the twain and sane packages.

The following is what you need to put into your code.
If class Scanner has found & could load either the twain (32bit Windows) or sane (Linux) library, then it will return a scanner object.
If you want the scanner object to signal events to certain classes/objects then you need to implement the ScannerListener interface:

public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata)

and you need to add the listening objects to the scanners listener list:

scanner.addListener(object);

An excerpt from the imageviewer project:


  package uk.co.mmscomputing.application.imageviewer;

  public class ScannerTab extends JPanel implements ScannerListener{

    Scanner scanner=null;

    public ScannerTab(){
      .
      .
      .

      scanner=Scanner.getDevice();
      if(scanner!=null){
        scanner.addListener(this);
        add(scanner.getScanGUI());
      }

      .
      .
      .
    }

    public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata){
      if(type.equals(ScannerIOMetadata.ACQUIRED)){
        BufferedImage img=metadata.getImage();             // acquired image as BufferedImage
        .
        .  do what you have to do
        .
      }else if(type.equals(ScannerIOMetadata.FILE)){  
        File file=metadata.getFile();                      // acquired image as file (twain only for the time being)
        .
        .  do what you have to do
        .
      }else if(type.equals(ScannerIOMetadata.NEGOTIATE)){  // (twain only in the moment)
        .
        .  negotiate default settings
        .
      }else if(type.equals(ScannerIOMetadata.STATECHANGE)){
        switch(metadata.getState()){
        .
        .  do what you have to do
        .
        }
        System.out.println("Scanner State "+metadata.getStateStr());
      }else if(type.equals(ScannerIOMetadata.INFO)){
        System.out.println(metadata.getInfo());
      }else if(type.equals(ScannerIOMetadata.EXCEPTION)){
        System.out.println(metadata.getException());
      }
    }
  }

  public void stop(){                                                    // execute before System.exit
    if(scanner!=null){                                                   // make sure user waits for scanner to finish!
      scanner.waitForNotBusy();
    }
  }

Projects :
  1. uk.co.mmscomputing.application.imageviewer:
    A simple Multi Page Image Viewer Applet. To view multipage *.sff, *.tiff and *.gif files. Twain and SANE test application.
  2. uk.co.mmscomputing.device.sane:
    This open source software project connects the world of java with SANE.SANE is an application programming interface standard used to access scanners & digital cameras ... .This project consists of a SANE frontend written in java.
  3. uk.co.mmscomputing.device.twain:
    This open source software project connects the world of java with TWAIN.TWAIN is an application programming interface standard used to access scanners & digital cameras ... .