hi im implimenting a gui applicaion so i have a list of shapes =>array of objects
and i want to select a shape from the list im stuck in implimenting the listener class
how do i know the selected object that is in my list it wont work with me
this is part of the code....

private JList list;
    private shape []shapesList= {new line(),new rectangle(),new oval()};
    private JLabel l1;
    private JComboBox bx1;
    private String[] clr={"red","yellow","green","blue","black"};
    private int selctIndex1,selectedIndx1;//will contain the index of the index (list,combo box)
    
    private class listHandler implements ListSelectionListener
    {
           public void valueChanged(ListSelectionEvent ev)
           {
               if(ev.getSource()==shapesList[0])
               {
//im stuck here how to do it
                   System.out.println("yubeeeeeee");
               }
           }
    }

your stuck at what exactly?
also, since you're shapes are not primitives, and ev.getSource returns an object, use the equals method to check for equality.

In your valueChanged method ev.getSource() will just be the list box itself, which you probably knew anyway. You can use list.getSelectedValue() to find out which object in the list is currently selected inside your valueChanged method.

ps @stultuske: in this particular case both getSource and getSelectedValue return the actual object in question, so an == test is appropriate.

commented: learning every day :) +12

Thanks very much...problem is solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.