Results 1 to 8 of 8

Thread: reading images

  1. #1
    utkarsh 1 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Post reading images

    hi....
    i want create a user interface.
    im using awt control list .list will contain name of the images.then user can choose one of the image from that list then the selected image will be read or displayed is it possible nd how

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: reading images

    read or displayed is it possible nd how
    Yes. You could write a program in java to do that.
    Why do it in AWT? Swing components have more and better UI.

    Post moved to New to Java

  3. #3
    utkarsh 1 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: reading images

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    /*<applet code="JComboboxdemo" width=300 height=100>
    
    </applet>
    */
    
    public class JComboboxdemo extends JApplet
    implements ItemListener {
    JLabel j1;
    ImageIcon ab,cdf,flower;
    public void init()  {
    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    
    JComboBox jc = new JComboBox();
    jc.addItem("ab");
    jc.addItem("cdf");
    jc.addItem("flower");
    
    jc.addItemListener(this);
    contentPane.add(jc);
    
    j1 = new JLabel(new ImageIcon("ab.jpg"));
    contentPane.add(j1);
    
    }
    
    public void itemStateChanged(ItemEvent ie) 
    {
    String s = (String)ie.getItem();
    j1.setIcon(new ImageIcon(s + " .jpg"));
    repaint();
    }
    }
    im not geting any error for this code but when i choose different image from the list while running it dsnt show that image
    Last edited by Norm; 01-01-2012 at 01:27 PM. Reason: added code tags

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: reading images

    Does the ImageIcon class constructor return a valid image?

  5. #5
    utkarsh 1 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: reading images

    yes when i choose any other option from the list it dsnt show anything

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: reading images

    The code works for me. Check that your images are correctly named and in the correct folders.

    I changed the code to build the filename first and print it out for debug before using it in the constructor.

  7. #7
    utkarsh 1 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: reading images

    images are in correct folder
    the images which is specified initially that image it displays bt when i choose different image from that list without closing the applet it dsnt show anything not even initial image

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: reading images

    Try this:
    build the image's filename first and print it out for debug before using it in the constructor.

Similar Threads

  1. reading pixel values from images
    By utkarsh 1 in forum Java 2D
    Replies: 18
    Last Post: 12-22-2011, 10:02 PM
  2. Replies: 0
    Last Post: 12-16-2010, 05:14 PM
  3. Replies: 4
    Last Post: 12-16-2010, 04:32 PM
  4. Replies: 5
    Last Post: 08-21-2009, 11:03 AM

Posting Permissions

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