急求一些Java代码

zisu123 2008-09-09 06:59:07
做一个GUI,上面有菜单栏(menubar),menu主要有file,edit等等。在file里面要有导入。我想让他导入一些jpg格式的图片到程序中。但是不会做导入这一块。
谁有源代码,我不胜感激!
还有一点,就是谁有对图片上的文字数字识别的Java源代码,有了最好!

我是想做一个这样的程序:大学的考试卷子都要存档,而现在的学生很多,又有很多科目,每年都会有很多卷子要存档。如果做一个程序,让纸质的卷子变成电子版,而且能够自动读取卷子上的学生信息,和数据库里的学生信息对照起来。
谢谢了!
...全文
141 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zisu123 2008-12-05
  • 打赏
  • 举报
回复
for (String extention : extentions)是什么意思?中间的冒号“:”是干什么用的?
zisu123 2008-12-05
  • 打赏
  • 举报
回复
for (String extention : extentions)是什么意思?中间的冒号“:”是干什么用的?
pzy123cn 2008-09-19
  • 打赏
  • 举报
回复
你这个商业性太强了
無名VF 2008-09-18
  • 打赏
  • 举报
回复
UP
Alien 2008-09-18
  • 打赏
  • 举报
回复
要识别图片好像有点难度哎!类似扫描了都。
bsr1983 2008-09-18
  • 打赏
  • 举报
回复
那你是要做图片识别啊?好像挺难的
zisu123 2008-09-16
  • 打赏
  • 举报
回复
ding
zisu123 2008-09-14
  • 打赏
  • 举报
回复
再顶
landyshouguo 2008-09-13
  • 打赏
  • 举报
回复
jf
shengli_liao 2008-09-13
  • 打赏
  • 举报
回复
帮顶...
zisu123 2008-09-13
  • 打赏
  • 举报
回复
不知还有没有更好的办法?
zisu123 2008-09-11
  • 打赏
  • 举报
回复
谢谢你,不知道还有没有更多的!
空间裂缝 2008-09-10
  • 打赏
  • 举报
回复
我给你个导入图片的程序
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView;

public class ImageJChooser {

public static void main(String[] args) {
ImageViewFrame iv = new ImageViewFrame();
iv.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
iv.setLocationRelativeTo(null);
iv.setVisible(true);
}

}

class ImageViewFrame extends JFrame {
private JLabel label = new JLabel();

private JFileChooser chooser;

public ImageViewFrame() {
setTitle("图片浏览");
setSize(300, 400);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("文件");
JMenuItem openItem = new JMenuItem("打开");
JMenuItem exitItem = new JMenuItem("退出");
menu.add(openItem);
menu.add(exitItem);
menuBar.add(menu);
openItem.addActionListener(new FileOpenListener());
exitItem.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
System.exit(0);

}

});
label = new JLabel();
add(label);
chooser = new JFileChooser();
ImageIcon imageicon = new ImageIcon(getClass()
.getResource("platte.jpg"));
final ExtentionFileFilter filter = new ExtentionFileFilter();
filter.addExtention("jpg");
filter.addExtention("jpeg");
filter.addExtention("gif");
filter.addExtention("bmp");
filter.setDescription("图片文件");
chooser.setFileFilter(filter);
chooser.setAccessory(new ImagePreViewer(chooser));
chooser.setFileView(new FileIconView(filter, imageicon));

}

private class FileOpenListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
chooser.setCurrentDirectory(new File("."));
// 显示 chooser 对话框
int result = chooser.showOpenDialog(ImageViewFrame.this);
if (result == JFileChooser.APPROVE_OPTION) {
String name = chooser.getSelectedFile().getPath();
label.setIcon(new ImageIcon(name));

}
}

}

}

/**
* 文件过滤类
*/
class ExtentionFileFilter extends FileFilter {
private String description = "";

private ArrayList<String> extentions = new ArrayList<String>();

public void addExtention(String extention) {
if (!extention.startsWith(".")) {
extention = "." + extention;
extentions.add(extention.toLowerCase());

}
}

public void setDescription(String aDescription) {
description = aDescription;

}

public boolean accept(File f) {
if (f.isDirectory()) {
return true;

}
String name = f.getName().toLowerCase();
for (String extention : extentions)
if (name.endsWith(extention))

return true;
return false;
}

public String getDescription() {
return description;
}

}

/**
* 打开对话框时默认的图片
*/
class FileIconView extends FileView {
private FileFilter filter;

private Icon icon;

public FileIconView(FileFilter aFilter, Icon aIcon) {
filter = aFilter;
icon = aIcon;

}

public Icon getIcon(File f) {
if (!f.isDirectory() && filter.accept(f))
return icon;
else
return null;

}
}

/**
* 加载存放图片的JLabel,刷新图片
*/
class ImagePreViewer extends JLabel {
public ImagePreViewer(JFileChooser chooser) {
setPreferredSize(new Dimension(200, 200)); //设置预览图片大小
setBorder(BorderFactory.createEtchedBorder()); // 创建一个不占用空间的空边框。
chooser.addPropertyChangeListener(new PropertyChangeListener() {

public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName() == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) {
// 用户选择了一个新的文件
File f = (File) evt.getNewValue();
if (f == null) {
setIcon(null);
return;

}
// 读取文件图标
ImageIcon icon = new ImageIcon(f.getPath());

// 如果文件太大或者太小,那么压缩它
if (icon.getIconWidth() > getWidth())
icon = new ImageIcon(icon.getImage().getScaledInstance(
getWidth(), -1, Image.SCALE_DEFAULT));

setIcon(icon);

}

}
});

}
}
zisu123 2008-09-09
  • 打赏
  • 举报
回复
有点像是把ACDSee嵌进去。但是没有ACDSee的Java代码

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧