jfile chooser


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

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:-)

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center