Vous êtes sur la page 1sur 3

package com.tieto.

scanner;
import ij.IJ;
import java.awt.Rectangle;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import uk.co.mmscomputing.device.scanner.Scanner;
import uk.co.mmscomputing.device.scanner.ScannerIOException;
/**
*
* @author ambatsur
*
*/
public class TestApplet extends JApplet {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
private JButton jButton1 = null;
private Scanner scanner;

//============================================================ main
public static void main(String[] args) {
//... Create an initialize the applet.
JApplet theApplet = new TestApplet();
//theApplet.init(); // Needed if overridden in applet
//theApplet.start(); // Needed if overridden in applet
//... Create a window (JFrame) and make applet the content pane.
JFrame window = new JFrame("Sample Applet and Application");
window.setContentPane(theApplet);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack(); // Arrange the components.
//System.out.println(theApplet.getSize());
window.setVisible(true); // Make the window visible.
}
//=============================================== Applet constructor
public TestApplet() {
initialize();
try {
scanner = Scanner.getDevice();
//scanner.addListener((ScannerListener) this);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void initialize() {
JFrame jf = new JFrame("Sample Applet and Application");
//jf.setContentPane(new TestApplet());
//jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//jf.pack(); // Arrange the components.
//System.out.println(theApplet.getSize());
//jf.setVisible(true); // Make the window visible.

//JFrame jf = new JFrame();


jf.setSize(300, 120);
jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jf.setResizable(false);
jf.setVisible(true);
jf.setContentPane(getJContentPane());
jf.setTitle("Scan");
jf.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
}
});
}

private JPanel getJContentPane() {


if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
}
return jContentPane;
}

private JButton getJButton() {


if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(4, 16, 131, 42));
jButton.setText("Select Device");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (scanner.isBusy() == false) {
selectDevice();
}
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(160, 16, 131, 42));
jButton1.setText("Scan");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
getScan();
}
});
}
return jButton1;
}

public void getScan() {


try {
scanner.acquire();
JComponent jc = scanner.getScanGUI();
System.out.println("jc ==>" + jc.getName());
} catch (ScannerIOException e1) {
IJ
.showMessage("Access denied! \nTwain dialog maybe already opened
!");
// e1.printStackTrace();
}
}

public void selectDevice() {


try {
scanner.select();
} catch (ScannerIOException e1) {
IJ.error(e1.toString());
}
}

Vous aimerez peut-être aussi