Hi frnds i struck with small problm when i click the next and - TopicsExpress



          

Hi frnds i struck with small problm when i click the next and previous button its not move into nxt and previous images pls hlp me. Photoviewer.java import java.awt.*; import java.awt.event.*; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.image.*; import javax.swing.filechooser.*; import java.util.HashMap; import java.io.*; public class PhotoViewer { public static void main(String args[]){ new Main(); } } class ImageDraw extends Canvas{ BufferedImage img; double radian=0.0; Dimension ds; int iw; int ih; int x; int y; int adjX; int adjY; int adjW; int adjH; int mX; int mY; int orWidth; int orHeight; boolean rotate; HashMap imgFiles; String filename; int curImgIndex; ImageDraw(){ ds=getToolkit().getScreenSize(); //get the screen size mX=(int)ds.getWidth()/2; //half of the screen width mY=(int)ds.getHeight()/2; //half of the screen height filename=null; //initialize filename variable rotate=false; //initialize rotate variable //initialize variables used to increase or decrease photo size adjX=0; adjY=0; adjW=0; adjH=0; } public void paint(Graphics g){ if(filename!=null){ if(rotate) //show rotated photo rotateImage(g); else showImage(g); //show normal and zoom photo } } //The rotateImage rotates the photo in clockwise or counterclockwise //direction based on the radian value public void rotateImage(Graphics g){ Graphics2D g2d=(Graphics2D)g; g2d.translate(mX,mY); //move the original coordinate to point(mX,mY) g2d.rotate(radian); //rotate the photo g2d.translate(-iw/2,-ih/2); //move the coordinate back to point (iw/2,ih/2) g2d.drawImage(img,0,0,iw,ih,null);//show the rotate photo g2d.dispose(); //clean the g2d object rotate=false; //reset the rotate to false after the photo rotates } //Increase the radian value by Math.PI/2 //so the photo is rotated in clockwise direction public void rotateClockwise(){ radian+=Math.PI/2; } //Decrease the radian value by Math.PI/2 //so the photo is rotated in countclockwise direction public void rotateCounterClockwise(){ radian-=Math.PI/2; } //The showImage method has code to display the photo when it is in //normal view or zoom view public void showImage(Graphics g){ Graphics2D g2d=(Graphics2D)g; g2d.translate(x,y); g2d.drawImage(img,0,0,iw,ih,null); g2d.dispose(); } public void readImage(String filename){ try{ //read the photo file so it is ready to display img=ImageIO.read(new File(filename)); //get the original width and height of the photo orWidth=img.getWidth(); orHeight=img.getHeight(); //Make sure the photo is not too large to fit the screen if(mX40){ adjX+=10; adjY+=10; adjW-=20; adjH-=20; setImageBounds(); } } //The storeImages method is invoked when the user select the Open... sub-menu //item from the program interface //It displays a file chooser dialog for multiple files selection //The selected photos file are stored in a HashMap object imgList for //later show public void storeImages(){ imgFiles=new HashMap(); JFileChooser chooser = new JFileChooser(E:\\); FileNameExtensionFilter filter = new FileNameExtensionFilter(Images, jpg, gif,png,bmp); chooser.setFileFilter(filter); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION) { File[] Files=chooser.getSelectedFiles(); for( int i=0;i
Posted on: Wed, 05 Mar 2014 13:20:16 +0000

Trending Topics



Recently Viewed Topics




© 2015