- 浏览: 83468 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
xx0326:
谢谢。楼主。哦。
js 检测身份证 -
triny1984:
。。。楼主也应该搞点文档说明一下吧。一个代码让人看起来有点纳闷 ...
flex、java聊天室 -
yexin218:
代码要格式化下,用编辑器里面代码工具import java.a ...
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 2951问题描述: c#与java MD5 加密后生成的结果 ... -
关于quartz任务调度的配置
2010-05-27 10:41 1024首先申明下,这方面资料和帖子太多了。本贴只是考虑个人记忆问题而 ... -
jdbc链接oracle数据库查询
2009-07-30 13:48 1454package com.zhuwei.util; impor ... -
js 检测身份证
2009-04-22 11:04 2326<!DOCTYPE HTML PUBLIC " ... -
java解析ubb2html
2009-04-03 18:59 1647package com.ztx.club.util; imp ... -
java正则实例大全
2009-03-17 12:45 2318众所周知,在程序开发 ... -
正则表达式提取html中的内容
2009-03-17 11:15 1539public class Test { publi ... -
java冒泡排序
2008-11-11 19:24 1070public class sorttest { publi ... -
论scjp5
2008-03-15 13:07 3292去年我买了一本scjp5.这个认证是sun公司的认证.说IT市 ...
相关推荐
功能说明: 环境说明: 开发软件:VS 2017 (版本2017以上即可,不能低于2017) 数据库:SqlServer2008r2(数据库版本无限制,都可以导入) 开发模式:mvc。。。
labview程序代码参考学习使用,希望对你有所帮助。
大米外贸商城系统 简称damishop 完全开源版,只需做一种语言一键开启全球133中语言自动翻译功能,价格实现自动汇率转换,集成微信支付宝 paypal以及国外主流支付方式,自带文章博客系统。 软件架构 基于MVC+语言包模式,增加控制台,API导入产品方便对接其他系统(带json示例数据)。 使用要求 PHP7.4+ MYSQL5.6+ REDIS(可选) 安装方法 composer install 打开安装向导安装 http://您的域名/install 特色 1、缓存层增加时间与批量like删除 2、API产品导入方便对接其他系统 3、增加控制台命令行,命令行生成语言翻译包 4、后台一键开启自动翻译模式,支持全球133中语言,由于google代理翻译需要收费,这个功能需要付费。 5、可选购物车与ajax修改购物车产品 6、一键结算checkout 7、增加网站前台自定义路由 方便seo 更新日志 v3.9.7 集成鱼码支付接口,方便个人站长即使收款到账使用 v3.9.3 更新内容 1:增加ueditor与旧编辑器切换 2:增加可视化布局插
labview程序代码参考学习使用,希望对你有所帮助。
labview程序代码参考学习使用,希望对你有所帮助。
毕设和企业适用springboot人工智能客服系统类及旅游规划平台源码+论文+视频