1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import javax.swing.text.html.parser.Element;
public class ListeRadio extends JPanel {
int i=0; //
// DECLARATION DES VARIABLES URL DES DIFFERENTES RADIOS
String rmc = ("C:\\Users\\pendoRa\\Music\\PTI\\rmc.mp3");
String rfm = ("C:\\Users\\pendoRa\\Music\\PTI\\rfm.mp3");
String nrj = ("C:\\Users\\pendoRa\\Music\\PTI\\nrj.mp3");
String skyrock = ("C:\\Users\\pendoRa\\Music\\PTI\\skyrock.mp3");
private static final long serialVersionUID = 1L;
public BookEntry books[] = {
// ITEMS DE LA JLIST DES RADIOS AVEC LIENS DES ICONES CORRESPONDANTS
// (INTITULE, ICONE, VARIABLE D'URL),
new BookEntry("NRJ", "image\\NRJ.jpg", nrj),
new BookEntry("RMC", "image\\RMC.jpg", rmc),
new BookEntry("RFM", "image\\RFM.jpg", rfm),
new BookEntry("SKYROCK", "image\\SKYROCK.jpg", skyrock)
};
JList booklist = new JList(books);
public JButton button = new JButton("Connect");
public ListeRadio() {
setLayout(new BorderLayout());
JButton button = new JButton("Connect");
booklist = new JList(books);
booklist.setCellRenderer(new BookCellRenderer());
booklist.setVisibleRowCount(4);
JScrollPane panez = new JScrollPane(booklist);
add(panez, BorderLayout.NORTH);
add(button, BorderLayout.SOUTH);
this.add(booklist);
booklist.setVisible(true);
}
public BookEntry getSelectedBookEntry() {
// TODO Auto-generated method stub
return (BookEntry) booklist.getSelectedValue();
}
public class PrintListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
int selected[] = booklist.getSelectedIndices();
System.out.println("Selected Elements <> : ");
for (int i = 0; i < selected.length; i++) {
BookEntry element = (BookEntry) booklist.getModel().getElementAt(selected[i]);
System.out.println(" " + element.string);
}
}
}
class BookEntry {
private final String title;
private final String imagePath;
private ImageIcon image;
private Object string;
// METHODE DE LA LISTE DES RADIO
// NOM, LIEN DE L'ICONE, ET VARIABLE D'URL
public BookEntry(String title, String imagePath, String string) {
this.title = title;
this.imagePath = imagePath;
this.string = string;
}
public String getTitle() {
// TODO Auto-generated method stub
return title;
}
public ImageIcon getImage() {
if(image == null) {
image = new ImageIcon(imagePath);
}
return image;
}
public String string() {
return null;
}
}
} |