DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: jfile chooser

  1. #1
    Join Date
    Nov 2003
    Posts
    1

    Question jfile chooser

    im a newbie in java and i just want to know why the code below doesnt work. everytime i press cancel or i pick an image from the open dialog box, the open dialog box opens again instead of closing it.
    Code:
    public void itemStateChanged(ItemEvent ie) 
      {
        JButton b = (JButton) e.getSource();
        Object s = dropdown.getSelectedItem();
        
             if (s == "Open")
          { 
            JFileChooser s= new JFileChooser();
            int t = s.showOpenDialog(this);
            if (t == JFileChooser.APPROVE_OPTION)
            {
              ImageIcon image = 
                new ImageIcon(s.getSelectedFile().getAbsolutePath());
              pictures[totalpics] = image;
              totalpics++;
            }
            else if (t == JFileChooser.CANCEL_OPTION)
            {
              pictures[totalpics] = null;
            }
          }
    
          resetImage(pictures[currentposition]);
        
      }
    [ArchAngel added CODE tags]

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    I'm confused by this line:
    Code:
    JButton b = (JButton) e.getSource();
    You never use 'b' and I don't see where 'e' is defined.

    Also, 'b', 's' and 't' are not very helpful variable names.

    Also, you don't check the contents of Strings like this:
    Code:
    if (s == "Open")
    You compare Strings using the .equals(...) method.
    ArchAngel.
    O:-)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links