Results 1 to 3 of 3

Thread: Please Help

  1. #1
    lackofcolor is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default Please Help

    I'm trying to slideshow images according from a path I chose from JFileChooser.
    Java Code:
    locate.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent colev) {
            chooser = new JFileChooser();
    		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    		
    		int ch2 = chooser.showOpenDialog(container);
    		
    		if(ch2 == JFileChooser.APPROVE_OPTION){
    			File path = chooser.getSelectedFile();
    			ImageViewer.this.setVisible(false);
    			showImg2 s = new showImg2();
    			s.showGUI(path);
    		}
          }
        });
    Java Code:
    public class showImg2 extends JFrame{
    AutoResize ar;
    JLabel canvas = new JLabel();
    File dir;
    	
    	class imageFilter implements FileFilter{
    		public boolean accept(File f){
    			String fileN = f.getName();
    			if(fileN.toLowerCase().endsWith(".jpg") ||
    			   fileN.toLowerCase().endsWith(".jpeg") ||	
    			   fileN.toLowerCase().endsWith(".gif") ||
    			   fileN.toLowerCase().endsWith(".png"))
    			{
    				return true;
    			}else{
    				return false;
    			}
    		}
    	}
    	
    	public void showGUI(File dir){
    		try{
    			setVisible(true);
    			setSize(600,600);
    			setLocationRelativeTo(null);
    			setDefaultCloseOperation(EXIT_ON_CLOSE);
    			
    			add(canvas);	
    			
    			this.dir = dir;
    			
    			File[] dir2 = dir.listFiles(new imageFilter());
    
    				for(int i=0; i<dir2.length; i++){
    					try{
    						BufferedImage image = ImageIO.read(new File(dir2[i].toString()));
    						ar = new AutoResize(image);
    						add(ar);
    						
    						canvas.setIcon(new ImageIcon(image));
    						
    						Thread.sleep(1000);
    					}catch(InterruptedException e){}
    				}
    			}catch(IOException e){e.printStackTrace();}
    	}
    }
    What could be wrong? Please reply ASAP. Thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What could be wrong?
    Who really knows? You never describe what your problem is.
    Please reply ASAP.
    This often doesn't help here as nobody likes to feel pressured, much less volunteers. I'm giving you this info as it may help you in future posts.

    Good luck.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Please explain your question more clearly. Know one knows what the question you have is. If you comes with an error message better to post it here and ask your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •