Cet article décrit la visionneuse d'images implémentée Java. Partagez-le pour votre référence. Les détails sont les suivants:
1. MyCanvas.java:
Package PictureViewer; Importer java.awt. *; Importer java.awt.event. *; import java.awt.image. int image_height; (this.getheight () - Image_Height) / 2, this);} public void ComponentResized (ComponentEvent e) {if (bi! = null) {System.out.println ("redimensive !!"); ; return; p0 "+ screen_proportion); image_width = bi.getWidth (this); image_height = bi.getheight (this); double image_proportion = 1.0 * image_height / i mage_width; System.out.println (" image: w "+ image_width +" "+ image_height +", p1 "+ image_proportion); if (image_proportion> screen_proportion) {image_height = screen_height; image_width = (int) (image_height / image_p roportion); system.out.println (" p1> p0 w = "+ image_width) ; ));2. MyFilter.java:
Package PictureViewer; import java.io.file; import java.io.filenameFilter; public class myFilter implémente filenameFilter {private string [] extensi on; "," .gif "," .gif "," .png "," .png "," .jpeg "," .jpeg "};} public myFilter (String [] extension) {this.extension = extension;} public booléen accepte (fichier dir, nom de chaîne) {pour (chaîne s: extension) {if (name.endswith (s)) {return true;}} return false;3. PictureViewer.java:
Package PictureViewer; import java.awt. *; import java.awt.event. *; import java.awt.image. *; import java.io. *; import javax.imageio. *; public class pictureViewer implémente ActionListener {private frame Cadre; ) lance l'exception {new PictureViewer (). init ();} public void init () {frame = new frame ("PictureViewer"); ; .Add (précédent); .Add (MC, "Centre"); }); Frame. ActionPerformed (ActionEvent E) {String Command = E.GetActionCommand (); ); ; Photo ")) {findEx ++; if (finsex> = files.length) finsex = files.length-1; this.display (files [finsex]);} this.validaButton ();} public void display (file f) {{ Try {BufferedImage BI = ImageIo.read (f); Mc.SetImage (BI); printStackTrace ();} mc.repaint ();} public void setIndex () {file current = new File (fPath + fname); ; i ++) {if (current.equals (fichiers [i])) {finals = i;}}}} public void validateButton () {précédemment.SetEnabled ((files! = null) && (find ex> 0)); Next.setEnabled ((Files! = NULL) && (FindEx <(Files.Length-1)));J'espère que cet article sera utile à la programmation Java de tous.