FileDocCategorySizeDatePackage
ListExample.javaAPI DocExample4106Mon Nov 09 12:45:54 GMT 1998None

ListExample

public class ListExample extends JPanel implements ActionListener

Fields Summary
private String[]
titles
private ImageIcon[]
bookImage
private JList
booklist
Constructors Summary
public ListExample()


      
        super(true);
        bookImage[0] = new ImageIcon("designjs.s.gif"); 
        bookImage[1] = new ImageIcon("expjava2.s.gif"); 
        bookImage[2] = new ImageIcon("javabeans.s.gif"); 
        bookImage[3] = new ImageIcon("javadata.s.gif"); 
        bookImage[4] = new ImageIcon("javadeluxe.s.gif"); 
        bookImage[5] = new ImageIcon("javafund.s.gif"); 
        bookImage[6] = new ImageIcon("javalang2.s.gif"); 
        bookImage[7] = new ImageIcon("javanetwk.s.gif"); 
        bookImage[8] = new ImageIcon("javavm.s.gif"); 
        bookImage[9] = new ImageIcon("javawt.s.gif"); 
        bookImage[10] = new ImageIcon("jenut.s.gif"); 
        bookImage[11] = new ImageIcon("jthreads.s.gif"); 
        bookImage[12] = new ImageIcon("javanut2.s.gif"); 
 
        this.setLayout(new BorderLayout());
        JButton button = new JButton("Print");
        button.addActionListener(this);

        booklist = new JList(titles);
        booklist.setCellRenderer(new BookCellRenderer());
        booklist.setVisibleRowCount(4);
        JScrollPane pane = new JScrollPane(booklist);

        add(pane, BorderLayout.NORTH);
        add(button, BorderLayout.SOUTH);
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)


        int selected[] = booklist.getSelectedIndices();
        System.out.println("Selected Elements:  ");

        for (int i=0; i < selected.length; i++) {
            String element = (String)booklist.getModel().
                                          getElementAt(selected[i]);
            System.out.println("  " + element);
        }
    
public static voidmain(java.lang.String[] s)

         JFrame frame = new JFrame("List Example");
         frame.addWindowListener(new BasicWindowMonitor());
         frame.setContentPane(new ListExample());
         frame.pack();
         frame.setVisible(true);