- 浏览: 81902 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
xx0326:
谢谢。楼主。哦。
js 检测身份证 -
triny1984:
。。。楼主也应该搞点文档说明一下吧。一个代码让人看起来有点纳闷 ...
flex、java聊天室 -
yexin218:
代码要格式化下,用编辑器里面代码工具<pre name= ...
javaAwt 实现照片浏览(初学者) -
343101272:
很好很强大
正则表达式提取html中的内容 -
javacto:
javacto 写道
呵呵 学长好& ...
java正则实例大全
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FilenameFilter;
import javax.imageio.ImageIO;
public class PictureViewer implements ActionListener{
private Frame frame;
private MyCanvas mc;
private String fpath;
private String fname;
private File[] files;
private int findex;
private FileDialog fd_load;
private MyFilter filter;
private Button previous;
private Button next;
public static void main(String[] args) {
new PictureViewer().init();
}
public void init(){
frame=new Frame("pictureViewer");
Panel pb=new Panel();
Button select=new Button("选择图片");
previous=new Button("上一张");
next=new Button("下一张");
select.addActionListener(this);
previous.addActionListener(this);
next.addActionListener(this);
pb.add(select);
pb.add(previous);
pb.add(next);
mc=new MyCanvas();
mc.setBackground(new Color(200,210,230));
mc.addComponentListener(mc);
frame.add(pb,BorderLayout.NORTH);
frame.add(mc,BorderLayout.CENTER);
frame.setSize(360,360);
frame.setLocation(400,200);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
frame.setVisible(true);
this.validateButton();
filter=new MyFilter();
fd_load=new FileDialog(frame,"打开文件",FileDialog.LOAD);
fd_load.setFilenameFilter(filter);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String commond=e.getActionCommand();
if(commond.equals("选择图片")){
fd_load.setVisible(true);
fpath=fd_load.getDirectory();
fname=fd_load.getFile();
if(fpath!=null&&fname!=null){
this.display(new File(fpath+fname));
files=new File(fpath).listFiles(filter);
this.setIndex();
}
}else if(commond.equals("上一张")){
findex--;
if(findex<0)
findex=0;
this.display(files[findex]);
}else if(commond.equals("下一张")){
findex++;
if(findex>=files.length)
findex=files.length-1;
this.display(files[findex]);
}
this.validateButton();
}
public void display(File f){
try{
BufferedImage bi=ImageIO.read(f);
mc.setImage(bi);
frame.setTitle("pictureViewer-["+f.getName()+"]");
}catch(Exception e){
e.printStackTrace();
}
mc.repaint();
}
public void setIndex(){
File current=new File(fpath+fname);
if(files!=null){
for(int i=0;i<files.length;i++){
if(current.equals(files[i])){
findex=i;
}
}
}
}
public void validateButton(){
previous.setEnabled((files!=null&&findex>0));
next.setEnabled((files!=null&&(findex<(files.length-1))));
}
}
class MyCanvas extends Canvas implements ComponentListener{
private BufferedImage bi;
private Image im;
private int image_width;
private int image_height;
public void setImage(BufferedImage bi){
this.bi = bi;
this.zoom();
}
public void paint(Graphics g){
g.drawImage(im,(this.getWidth()-image_width)/2,(this.getHeight()-image_height)/2,this);
}
public void componentResized(ComponentEvent e){
if(bi != null){
this.zoom();
this.repaint();
}
}
public void componentMoved(ComponentEvent e){}
public void componentShown(ComponentEvent e){}
public void componentHidden(ComponentEvent e){}
public void zoom(){
if(bi == null)
return;
int screen_width = this.getWidth();
int screen_height = this.getHeight();
double screen_proportion = 1.0 * screen_height / screen_width;
image_width = bi.getWidth(this);
image_height = bi.getHeight(this);
double image_proportion = 1.0 * image_height / image_width;
if(image_proportion > screen_proportion){
image_height = screen_height;
image_width = (int)(image_height / image_proportion);
}else{
image_width = screen_width;
image_height = (int)(image_width * image_proportion);
}
im = bi.getScaledInstance(image_width,image_height,Image.SCALE_SMOOTH);
}
}
class MyFilter implements FilenameFilter{
private String[] extension;
public MyFilter(){
extension = new String[]{".jpg", ".JPG", ".gif", ".GIF", ".png", ".PNG", ".jpeg", ".JPEG"};
}
public MyFilter(String[] extension){
this.extension = extension;
}
public boolean accept(File dir,String name){
for(String s : extension){
if(name.endsWith(s)){
return true;
}
}
return false;
}
}
评论
import java.awt.BorderLayout; import java.awt.Button; import java.awt.Canvas; import java.awt.Color; import java.awt.FileDialog; import java.awt.Frame; import java.awt.Graphics; import java.awt.Image; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.FilenameFilter; import javax.imageio.ImageIO; public class PictureViewer implements ActionListener{ private Frame frame; private MyCanvas mc; private String fpath; private String fname; private File[] files; private int findex; private FileDialog fd_load; private MyFilter filter; private Button previous; private Button next; public static void main(String[] args) { new PictureViewer().init(); } public void init(){ frame=new Frame("pictureViewer"); Panel pb=new Panel(); Button select=new Button("选择图片"); previous=new Button("上一张"); next=new Button("下一张"); select.addActionListener(this); previous.addActionListener(this); next.addActionListener(this); pb.add(select); pb.add(previous); pb.add(next); mc=new MyCanvas(); mc.setBackground(new Color(200,210,230)); mc.addComponentListener(mc); frame.add(pb,BorderLayout.NORTH); frame.add(mc,BorderLayout.CENTER); frame.setSize(360,360); frame.setLocation(400,200); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ System.exit(0); } }); frame.setVisible(true); this.validateButton(); filter=new MyFilter(); fd_load=new FileDialog(frame,"打开文件",FileDialog.LOAD); fd_load.setFilenameFilter(filter); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub String commond=e.getActionCommand(); if(commond.equals(" 选择图片")){ fd_load.setVisible(true); fpath=fd_load.getDirectory(); fname=fd_load.getFile(); if(fpath!=null&&fname!=null){ this.display(new File(fpath+fname)); files=new File(fpath).listFiles(filter); this.setIndex(); } }else if(commond.equals("上一张")){ findex--; if(findex<0) findex=0; this.display(files[findex]); }else if(commond.equals("下一张")){ findex++; if(findex>=files.length) findex=files.length-1; this.display(files[findex]); } this.validateButton(); } public void display(File f){ try{ BufferedImage bi=ImageIO.read(f); mc.setImage(bi); frame.setTitle("pictureViewer-["+f.getName()+"]"); }catch(Exception e){ e.printStackTrace(); } mc.repaint(); } public void setIndex(){ File current=new File(fpath+fname); if(files!=null){ for(int i=0;i<files.length;i++){ if(current.equals(files[i])){ findex=i; } } } } public void validateButton(){ previous.setEnabled((files!=null&&findex>0)); next.setEnabled((files!=null&&(findex<(files.length-1)))); } } class MyCanvas extends Canvas implements ComponentListener{ private BufferedImage bi; private Image im; private int image_width; private int image_height; public void setImage(BufferedImage bi){ this.bi = bi; this.zoom(); } public void paint(Graphics g){ g.drawImage(im,(this.getWidth()-image_width)/2,(this.getHeight()-image_height)/2,this); } public void componentResized(ComponentEvent e){ if(bi != null){ this.zoom(); this.repaint(); } } public void componentMoved(ComponentEvent e){} public void componentShown(ComponentEvent e){} public void componentHidden(ComponentEvent e){} public void zoom(){ if(bi == null) return; int screen_width = this.getWidth(); int screen_height = this.getHeight(); double screen_proportion = 1.0 * screen_height / screen_width; image_width = bi.getWidth(this); image_height = bi.getHeight(this); double image_proportion = 1.0 * image_height / image_width; if(image_proportion > screen_proportion){ image_height = screen_height; image_width = (int)(image_height / image_proportion); }else{ image_width = screen_width; image_height = (int)(image_width * image_proportion); } im = bi.getScaledInstance(image_width,image_height,Image.SCALE_SMOOTH); } } class MyFilter implements FilenameFilter{ private String[] extension; public MyFilter(){ extension = new String[]{".jpg", ".JPG", ".gif", ".GIF", ".png", ".PNG", ".jpeg", ".JPEG"}; } public MyFilter(String[] extension){ this.extension = extension; } public boolean accept(File dir,String name){ for(String s : extension){ if(name.endsWith(s)){ return true; } } return false; } }
发表评论
-
java与c#MD5加密后结果不一致问题
2011-04-08 22:50 2825问题描述: c#与java MD5 加密后生成的结果 ... -
关于quartz任务调度的配置
2010-05-27 10:41 977首先申明下,这方面资料和帖子太多了。本贴只是考虑个人记忆问题而 ... -
jdbc链接oracle数据库查询
2009-07-30 13:48 1422package com.zhuwei.util; impor ... -
js 检测身份证
2009-04-22 11:04 2287<!DOCTYPE HTML PUBLIC " ... -
java解析ubb2html
2009-04-03 18:59 1601package com.ztx.club.util; imp ... -
java正则实例大全
2009-03-17 12:45 2282众所周知,在程序开发 ... -
正则表达式提取html中的内容
2009-03-17 11:15 1496public class Test { publi ... -
java冒泡排序
2008-11-11 19:24 1033public class sorttest { publi ... -
论scjp5
2008-03-15 13:07 3250去年我买了一本scjp5.这个认证是sun公司的认证.说IT市 ...
相关推荐
java实现画图编辑器,主要实现的功能有,线,圆,矩形(读者可自己添加),以及图像的保存,打开,画笔颜色的选择
java awt实现读取和生成excel 、mysql
Java AWT组件综合练习,list choice button textArea 等
采用面向对象的思路,实现中国象棋可联机版本,适合初学者,以及对面向对象有更深层次理解的开发者或者同学。 使用原生的java awt、Swing进行窗口式开发 将素材文件夹放在D:\Game路径下 两个工程直接导入Eclipse,...
java awt swing 实现计算器源代码
本论文在剖析Java虚拟机内部实现机 制的基础上,着重讨论了在嵌入式系统中实现AWT技术的过程。并且在实现AWT技术的 基础上,讨论了如何根据J2ME规范来进行AWT类库的构建。 是一篇很好的学习论文。
Java AWT 教程
4.1 AWT工具集简介 4.2 AWT事件模型 4.3 GUI组件上的图形操作 4.4 常用的AWT组件
AWT的例子 适合初学者 已经通过验证 正确可以运行
Java的AWT包.pdf 学习资料 复习资料 教学资源
java awt swt swing gui 教程 pdf
实用awt 控件
java绘图 java awt 经典绘图的例子,对于初学awt模块的人非常有帮助.
嵌入式系统中Java AWT的实现.pdf
awt包java Android awt包java Android awt包java Android awt包java Android awt包java Android awt包java Android awt包java Android awt包java Android awt包java Android awt包java Android awt包java Android ...
JAVA AWT实现的贪吃蛇游戏。 含jar可执行文件(可看效果)。
javaAWT组件JSlider应用javaAWT组件JSlider应用javaAWT组件JSlider应用
廉价,超精简,连加,连乘,四则运算。心血自编的全awt 版java计算器!
图书管理系统(JAVA的AWT实现)。 感觉比较少有,纯粹是为了熟悉下JAVA的AWT,大家也可以下载去熟悉下!