代码拉取完成,页面将自动刷新
同步操作将从 yushulx/JavaTwain 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import net.sf.jni4net.Bridge;
import java.io.IOException;
import javatwain.DotNetScanner;
import javatwain.IJavaProxy;
import javatwain.INativeProxy;
public class ScanDocuments extends JPanel
implements ActionListener, INativeProxy {
private JButton mLoad, mScan;
private JFileChooser mFileChooser;
private JLabel mImage;
private String mResult;
private IJavaProxy mScanner;
private JComboBox mSourceList;
private String[] mSources;
public ScanDocuments() {
super(new BorderLayout());
initTWAIN();
//Create a file chooser
mFileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
".png", "png");
mFileChooser.setFileFilter(filter);
mLoad = new JButton("Load");
mLoad.addActionListener(this);
mScan = new JButton("Scan");
mScan.addActionListener(this);
// get sources
mSources = mScanner.GetSources();
if (mSources != null) {
mSourceList = new JComboBox(mSources);
}
else {
mSourceList = new JComboBox(new String[]{"N/A"});
}
mSourceList.setSelectedIndex(0);
// button panel
JPanel buttonPanel = new JPanel();
buttonPanel.add(mSourceList);
buttonPanel.add(mScan);
buttonPanel.add(mLoad);
add(buttonPanel, BorderLayout.PAGE_START);
// image panel
JPanel imageViewer = new JPanel();
mImage = new JLabel();
mImage.setSize(480, 640);
imageViewer.add(mImage);
add(imageViewer, BorderLayout.CENTER);
}
private void initTWAIN() {
try {
Bridge.init();
Bridge.LoadAndRegisterAssemblyFrom(new java.io.File("JavaTwain.j4n.dll"));
}
catch (Exception e) {
e.printStackTrace();
}
mScanner = new DotNetScanner();
mScanner.RegisterListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == mLoad) {
int returnVal = mFileChooser.showOpenDialog(ScanDocuments.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = mFileChooser.getSelectedFile();
mImage.setIcon(new ImageIcon(file.toPath().toString()));
}
}
else if (e.getSource() == mScan) {
if (mSources == null)
return;
String sourceName = (String)mSourceList.getSelectedItem();
int len = mSources.length;
int index = 0;
for (index = 0; index < len; ++index) {
if (mSources[index].equals(sourceName)) {
break;
}
}
mScanner.AcquireImage(index);
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//JOptionPane.showMessageDialog(null, "refresh");
mScanner.CloseSource();
}
};
int delay = 1; //milliseconds
Timer timer = new Timer(delay, taskPerformer);
timer.setRepeats(false);
timer.start();
}
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Scan Documents");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frame.add(new ScanDocuments());
//Display the window.
frame.pack();
frame.setVisible(true);
frame.setResizable(false);
frame.setSize(480, 700);
double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
double height = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
int frameWidth = frame.getWidth();
int frameHeight = frame.getHeight();
frame.setLocation((int)(width - frameWidth) / 2, (int)(height - frameHeight) / 2);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
public boolean Notify(String message, String value) {
mImage.setIcon(new ImageIcon(value));
return true;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。