この記事では、Java Implemented Image Viewerについて説明します。参照のためにそれを共有してください。詳細は次のとおりです。
1。mycanvas.java:
PictureViewer; Import java.awt。*; java.awt.imageをインポートしますint image_height; (this.getheight() - image_height)/2、this); ; this.repaint(); return screen_width = getWidth(); p0 "+screen_propiortion); image_width = bi.getWidth(this); image_height = bi.getheight(this); double image_propirtion = 1.0 * image_height / i mage_width; system.out.println(" image:w "+image_width+"、h "+image_height+"、p1 "+image_propirporter); if(image_propirportion> screen_propirporty){emage_height = screen_height; image_width =(int)(image_height / image_p roportion); system.out.println(" p1> p0 w = "+image_width) ; else {image_width; image_width * system.out.println( "p0> h ="+image_height); );2。myfilter.java:
パッケージPictureViewer; Import java.io.file; import java.io.filenamefilter; public class myfilterはfilenamefilter {private string [] extendi [] {"。jpg"、 ".jpg "、" .gif "、" .gif "、" .png "、" .png "、" .jpeg "、" .jpeg "};} public myfilter(string [] extension){this.extension = extension;} public boolean accept(file dir、string name){string s:extension){name.endswith(s)){return true;3。PictureViewer.java:
パッケージPictureViewer; Import java.awt。*; import java.awt.event。*; import java.awt.image。*; import java.io。*; import javax.imageio。プライベートな弦楽団体。 )スロー{new PictureViewer()。 ;以前のボタン(「次」); .add(以前); .Add(MC、 "Center"); }) ActionPerformed(ActionEvent e){String command = e.getActionCommand( "command.equals(" select picture "){fd_load.setvisible(true); );(fpath!= null)&&(null)){new file(fpath + fname); ; elfer( "前"){findex <0)findex = 0;写真 ")){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); printStackTrace(); MC.Repaint(); ; i ++){if(current.equals(files [i])){findex = i; next.setEnabled((files!= null)&&(findex <(files.length-1))}}}この記事がみんなのJavaプログラミングに役立つことを願っています。