有大神帮帮忙改个applet么。小弟感激不尽。。
applet吧
全部回复
仅看楼主
level 2
skip77 楼主
一个java改成applet。。求帮助。我需要用。。实在改不来。有好心人帮改下么。 急用。[泪]
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Hashtable;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.swing.JPanel;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import net.sf.fmj.ui.application.CaptureDeviceBrowser;
import net.sf.fmj.ui.application.ContainerPlayer;
import net.sf.fmj.ui.application.PlayerPanelPrefs;
public class CameraFrame extends JFrame{
public static void main(String[] args)throws Exception {
CameraFrame camera = new CameraFrame();camera.setVisible(true);
}
public CameraFrame() throws Exception{
this.setTitle("摄像头读取二维码应用");
this.setSize(480, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel cameraPanel = new JPanel();
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(cameraPanel, BorderLayout.CENTER);
ContainerPlayer containerPlayer = new ContainerPlayer(cameraPanel);
MediaLocator locator = CaptureDeviceBrowser.run(null); //弹出摄像头设备选择
PlayerPanelPrefs prefs = new PlayerPanelPrefs();
containerPlayer.setMediaLocation(locator.toExternalForm(), prefs.autoPlay);
new Thread() {
public void run() {
while (true) {
try {
Thread.sleep(1000);
Dimension imageSize = cameraPanel.getSize();
BufferedImage image = new BufferedImage(
imageSize.width, imageSize.height,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
cameraPanel.paint(g);
g.dispose();
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Hashtable hints = new Hashtable();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); //指定编码,否则中文会乱码
Result result = new MultiFormatReader().decode(bitmap, hints);
System.out.println("二维码解析结果:" + result.getText());
System.exit(0);
} catch (Exception re) {
System.out.println("扫描不到...");
re.printStackTrace();
}
}
}
}.start();
}
}
2013年05月25日 07点05分 1
1