IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

Icones sur JList


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut Icones sur JList
    Bonjour, avant de poster un quelquonque code, je pose d'abord la question est-il possible de placer devant chaque Item d'une JList des petits icônes correspondants? Des sortes de logos si vous voulez.

    Merci bien.

  2. #2
    Expert éminent
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Billets dans le blog
    1
    Par défaut
    Salut,


    Il faut définir son propre renderer en étendant DefaultListCellRenderer, et l'associer à la JList via setCellRenderer...


    a++

  3. #3
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Merci beaucoup, cette méthode me parait parfaitement adéquat par rapport à mes attentes.

    Edit :
    J'ai une erreur de débutant ! Mais je ne comprend pas pourquoi elle se manifeste ? J'ai le droit a un bon vieux "java.lang.NoSuchMethodError: main"
    alors que je n'ai pas touché au main je poste mon code tout entier :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.beans.XMLEncoder;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
     
    import javax.swing.DefaultComboBoxModel;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.JScrollPane;
    import javax.swing.ListCellRenderer;
    import javax.swing.filechooser.FileNameExtensionFilter;
     
    import org.jdom.Document;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    import org.jdom.xpath.XPath;
     
    @SuppressWarnings("serial")
     
             class Radio {
            	public static String rmc;
     
    			public Radio() { 
     
            		  String rmc = "http://www.rmc.fr";
     
     
            	 }
             }
     
    public class FenetrePrincipale extends JFrame
     
        implements ActionListener, MouseListener
    {
     
        public interface liste {
     
    	}
    	private static 			JPanel 					    panneau; // private STATIC pour utiliser panneau dans d'autre classes
        private 				JPanel 					    statusbar;
        private 				JLabel 					    status;
        private 				GridBagConstraints 		    c;
        private 				String 					    labels[] = {"          RMC    ", "          France Info          ", "          FunRadio    ", "          Skyrock    ", "          Radiox    ", "          Radioy    " };
        private 				String 					    labelsFav[] = {"WebRadios(par défaut)", "Mes Radios Favorites" };
        private 				DefaultComboBoxModel 	    model;
        private 				JComboBox			        comboBox;
        private 				JList 					    liste;
        private 				JScrollPane                 scrollPane;
        private 				JButton 				    boutonConnexion;
        private 				JButton 				    boutonExit;
        private 				JFileChooser 			    chooser;
        private 				FileNameExtensionFilter     filter;
        private 				JMenuBar 					menubar;
        private 				JMenu 						menuFichier;
        private 				JMenu 						menuPreferences;
        private 				JMenu 						menuAide;
        private 				JMenuItem 					itemConnect;
        private 				JMenuItem				    itemExit;
        private 				JMenuItem	 				itemCfg;
        private 				JMenuItem		 			itemHelp;
        private 				JMenuItem				 	itemBlog;
        private 				JMenuItem 				 	itemInfo;
        private 	Object 		xpa;
        private				    String chemin;
        private 				JProgressBar bar;  // private STATIC pour utiliser JProgressBar dans d'autre classes
        int 					min = 0;
        int 					max = 100;
        int 					i; 
        int						j;
     
     
     
     
     
     
        @SuppressWarnings("deprecation")
    	public FenetrePrincipale() {
     
     
     
        	            super("PTI JAVA 2010 BENOIT POURVILLE");
            panneau 			= 				new JPanel(new GridBagLayout());
     
            statusbar		    = 				new JPanel(new GridBagLayout());
            status 				= 				new JLabel("PTI 2010 IGD BENOIT POURVILLE");
            c 					= 				new GridBagConstraints();
            model 				= 				new DefaultComboBoxModel(labels);
            comboBox		    = 				new JComboBox(labelsFav);
            liste 				= 				new JList(model);
            scrollPane 			= 				new JScrollPane(liste);
            boutonConnexion     =			    new JButton("Connexion!");
            boutonExit		    =			    new JButton("Quitter");     
            chooser 			= 				new JFileChooser();
     
            filter 				= 				new FileNameExtensionFilter("Fichiers Exécutables", new String[] {"exe"}); // Filtre du JFC pour n'accepter que les executables
            menubar			    = 				new JMenuBar();
            menuFichier 		= 				new JMenu("Fichier");
            menuPreferences 	= 				new JMenu("Préférences");
            menuAide 			= 				new JMenu("?");
     
            itemConnect 		= 				new JMenuItem("Se Connecter");
            itemExit 			= 				new JMenuItem("Quitter");
            itemCfg 			= 				new JMenuItem("Configurer...");
            itemHelp 			= 				new JMenuItem("Aide");
            itemBlog 			= 				new JMenuItem("Visiter le Blog...");
            itemInfo 			= 				new JMenuItem("A propos...");
     
            bar 				= 				new JProgressBar();
     
     
            bar.setMinimum(min);
            bar.setMaximum(max);
            bar.setBorderPainted(true);
     
            c.weightx = 1.0D;
            c.weighty = 0.5D;
            c.anchor = 14;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 4;
            c.gridy = 3;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(bar, c);
     
     
            boutonConnexion.setActionCommand("boutonConnexion"); 
            itemConnect.setActionCommand("boutonConnexion");
     
            itemCfg.setActionCommand("Configurer");
     
     
            boutonConnexion.setForeground(Color.WHITE);
            boutonConnexion.setBackground(Color.BLACK);
            boutonConnexion.addMouseListener(new MouseAdapter() {
     
     
     
                public void mouseEntered(MouseEvent e)
                {
                    boutonConnexion.setForeground(Color.BLACK);
                    boutonConnexion.setBackground(Color.GRAY);
                }
            });
            boutonConnexion.addMouseListener(new MouseAdapter() {
     
            	public void mouseExited(MouseEvent e)
                {
                    boutonConnexion.setForeground(Color.GRAY);
                    boutonConnexion.setBackground(Color.BLACK);
                }
            });
     
     
            boutonExit.setBackground(Color.BLACK);
            boutonExit.setForeground(Color.WHITE);
            boutonExit.addActionListener(new Exit());
            boutonExit.addMouseListener(new MouseAdapter() {
     
                public void mouseEntered(MouseEvent e)
                {
                    boutonExit.setForeground(Color.BLACK);
                    boutonExit.setBackground(Color.GRAY);
                }
            });
            boutonExit.addMouseListener(new MouseAdapter() {  // bouton exit changement couleur au survolage
     
                public void mouseExited(MouseEvent e)
                {
                    boutonExit.setForeground(Color.GRAY);
                    boutonExit.setBackground(Color.BLACK);
                }
            });
     
            panneau.add(statusbar);
            statusbar.add(status);
     
     
            c.weightx = 1.0D;
            c.weighty = 0.0D;
            c.anchor = 13;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 2;
            c.gridy = 1;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(comboBox, c);
     
     
            comboBox.addActionListener(new ActionListener() {
     
                public void actionPerformed(ActionEvent arg0)
                {
                    System.out.println("Liste radio par defaut / Liste utilisateur");
                    comboBox.getItemListeners();
                }
            });
     
            // Commentaires a refaire sur la position des boutons
            c.weightx = 1.0D;
            c.weighty = 0.0D;
            c.anchor = 10;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 2;
            c.gridy = 2;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(liste, c);
            liste.setBackground(Color.GRAY);
     
     
     
            c.weightx = 1.0D;
            c.weighty = 0.0D;
            c.anchor = 18;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 1;
            c.gridy = 1;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(boutonConnexion, c);
     
     
     
     
     
     
            // ON commence par lire le fichier XML de config meme si il n'est pas encore CONFIG
     
        	SAXBuilder sxb = new SAXBuilder();
            Document document = null;
            try
            {
                document = sxb.build(new File("config.xml"));
                org.jdom.Element racine = document.getRootElement();
                XPath xpa = null;
                xpa = XPath.newInstance("//string");
                chemin = xpa.valueOf(racine);
            }
            catch(JDOMException e1)
            {
                e1.printStackTrace();
            }
            catch(IOException e1)
            {
                e1.printStackTrace();
            }
     
     
            System.out.println("DEBUG    :  ");
            System.out.println(chemin);
            System.out.println(Radio.rmc);
     
     
     
           //////////////// 
     
     
     
            c.weightx = 1.0D;
            c.weighty = 0.5D;
            c.anchor = 14;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 4;
            c.gridy = 4;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(boutonExit, c);
     
     
     
            itemBlog.addActionListener(new Blog());
            itemHelp.addActionListener(new Help());
            itemInfo.addActionListener(new Info());
            itemExit.addActionListener(new Exit());
     
     
            boutonConnexion.addActionListener(this);
     
     
            itemCfg.addActionListener(this);
            itemConnect.addActionListener(this); 
     
            Container contentPane = getContentPane();
            contentPane.add(scrollPane, "Center");
            scrollPane.createVerticalScrollBar();
     
     
            panneau.add(scrollPane);
            panneau.add(menubar);
     
     
            menubar.add(menuFichier);
            menubar.add(menuPreferences);
            menubar.add(menuAide);
            menuFichier.add(itemConnect);
            menuFichier.addSeparator();
            menuFichier.add(itemExit);
            menuPreferences.add(itemCfg);
            menuAide.add(itemHelp);
            menuAide.add(itemBlog);
            menuAide.addSeparator();
            menuAide.add(itemInfo);
     
     
            chooser.setFileFilter(filter); // filtre sur le JFileChooser ( "exe" )
            setLayout(new BorderLayout(9, 3));
     
            add(panneau, "Center");
            add(statusbar, "South");
            setResizable(false); // interdiction de redimmentioner la fenêtre
            setVisible(true); 
            panneau.setBackground(Color.darkGray); // Fond gris foncé..
            setSize(800, 400); // taille fenêtre 600x400 pxl
            setJMenuBar(menubar);  
            show();
        }
     
         @SuppressWarnings("deprecation")
    	public void actionPerformed(ActionEvent aActionEvent) {
     
        		String action = aActionEvent.getActionCommand();
     
        		    if(action.equals("Configurer")) // Fonction Configuration
        		{
        			if(this.chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
        			{
        				chemin = (chooser.getSelectedFile().getAbsolutePath());
        				System.out.println(chemin);
        			}
     
     
        			xpa = null;
        	        try
        	        {
        	            xpa = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("config.xml")));  // Fonction pour creer fichier xml
        	            ((XMLEncoder) xpa).writeObject(chemin);
        	            System.out.println(xpa);
     
        	        }
        	        catch(FileNotFoundException e1)
        	        {
        	            e1.printStackTrace();
        	        }
     
        	        ((XMLEncoder) xpa).close();
     
        		}
     
        		if(action.equals("boutonConnexion")&&(chemin==null)) // Si le fichier Config est vierge ouverture de la fenetre de config
     
        		{
        			System.out.println("Aucune configuration trouvée...");
        			System.out.println(chemin);
     
        			JOptionPane pane = new JOptionPane(); 
        			int option = JOptionPane.showConfirmDialog(null, "Veuillez Configurer votre Lecteur Multimedia", "INFORMATION", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        			pane.show();
     
        			if(option == JOptionPane.OK_OPTION)
        			{
        				System.out.println("Go configurer");
     
        				this.chooser.showOpenDialog(this);
     
        				}
        			else 
        				System.out.println("Retour au menu principal");
     
        		}
     
        		if(action.equals("boutonConnexion")&&(chemin!=null)) // Fichier configuration OK : Execution du Lecteur avec la commande propre a la Station
     
        		{
        			for (int j=0; j<=100; j++) // Fonction de la progress Bar
        			{
     
        			bar.setValue(j);
     
        			}
     
        			try {
    					Thread.sleep(100);
    				} catch (InterruptedException e) {
     
    					e.printStackTrace();
    				} 
        		}
     
        				try {
        					String rmc = Radio.rmc;
    						Runtime.getRuntime().exec(new String[] {chemin } );
    					} catch (IOException e) {
     
    						e.printStackTrace();
    					} 
     
        			    System.out.println(chemin);
        			    System.out.println("Debug 2 : radio :");
     
     
        			}						               //	"http://pendora.fr.nf:8000/listen.pls"
     
     
     
         public class ListEx extends JPanel { 
     
        	    /**
                     * 
                     */
    		private static final long serialVersionUID = 1L;
     
    			private BookEntry books[] = {
        	    		new BookEntry("Ant : blabla", "shortIcon.jpg"),
        	    		new BookEntry("DTB blabla", "longIcon.jpg")
     
        	    };
     
        	    private JList booklist = new JList(books);
     
        	    public ListEx() {
        	    	setLayout(new BorderLayout());
        	    	JButton button = new JButton("Connect");
        	    	button.addActionListener(new PrintListener());
     
        	    	booklist = new JList(books);
        	    	booklist.setCellRenderer(new BookCellRenderer());
        	    	booklist.setVisibleRowCount(4);
        	    	JScrollPane panez = new JScrollPane(booklist);
     
        	    	add(panez, BorderLayout.NORTH);
        	    	add(button, BorderLayout.SOUTH);
     
        	    }
     
        	    class PrintListener implements ActionListener {
        	    	public void actionPerformed(ActionEvent e) {
        	    		int selected[] = booklist.getSelectedIndices();
        	    		System.out.println("Selected Elements :  ");
     
        	    		for (int f = 0; i < selected.length; i++) {
        	    			BookEntry element = (BookEntry) booklist.getModel().getElementAt(selected[i]);
        	    			System.out.println("   " + element.getTitle());
     
        	    			}
        	    		}
        	    	}
        	    }
     
        	    class BookEntry {
        	    	private final String title;
     
        	    	private final String imagePath;
     
        	    	private ImageIcon image;
     
        	    	public BookEntry(String title, String imagePath) {
        	    		this.title = title;
        	    		this.imagePath = imagePath;
     
        	    	}
     
    				public String getTitle() {
    					// TODO Auto-generated method stub
    					return title;
    				}
    				public ImageIcon getImage() {
    					if(image == null) {
    						image = new ImageIcon(imagePath);
    					}
     
        	    	return image;
        	    }
     
        	    public String toString() {
        	    	return title;
        	    }
        	}
     
        	@SuppressWarnings("serial")
    		static class BookCellRenderer extends JLabel implements ListCellRenderer {
     
        		private final Color HIGHLIGHT_COLOR = new Color(0, 0, 128);
     
        		public BookCellRenderer() {
        			setOpaque(true);
        			setIconTextGap(12);
        		}
     
        		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        			BookEntry entry = (BookEntry) value;
        			setText(entry.getTitle());
        			setIcon(entry.getImage());
        			if(isSelected) {
        				setBackground(HIGHLIGHT_COLOR);
        				setForeground(Color.white);
        			} else {
        				setBackground(Color.white);
        				setForeground(Color.black);
        			}
        			return this;
        			}
     
     
     
     
    public static void main(String args[]) { // Ou est le probleme mon appli a toujours fonctionnée jusqu'a que je rajoute cet exemple de JList avec icones !
     
    	new FenetrePrincipale();
     
     
    			}
        	}
     
     
     
     
    		public void mouseClicked(MouseEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mouseEntered(MouseEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mouseExited(MouseEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mousePressed(MouseEvent arg0) {
    			// TODO Auto-generated method stub
     
    		}
     
    		@Override
    		public void mouseReleased(MouseEvent arg0) {
    			// TODO Auto-generated method stub
    		}
    }
    Merci a vous.

  4. #4
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Tu as mis le main dans la classe interne ListEx au lieu de le mettre dans la classe correspondant au fichier (à savoir FenetrePrincipale).

  5. #5
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Problème résolu merci.

    Je poste mes 2 classes pour le principe.

    La classe FenetrePrincipale :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.beans.XMLEncoder;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
     
    import javax.swing.DefaultComboBoxModel;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JProgressBar;
    import javax.swing.JScrollPane;
    import javax.swing.ListCellRenderer;
    import javax.swing.filechooser.FileNameExtensionFilter;
     
    import org.jdom.Document;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    import org.jdom.xpath.XPath;
     
    @SuppressWarnings("serial")
     
             class Radio {
            	public static String rmc;
     
    			public Radio() { 
     
            		  String rmc = "http://www.rmc.fr";
     
     
            	 }
             }
     
    public class FenetrePrincipale extends JFrame
     
        implements ActionListener, MouseListener
    {
        public static void main(String args[]) { 
     
    	new FenetrePrincipale();	
     
    }
     
    	private static 			JPanel 					    panneau; // private STATIC pour utiliser panneau dans d'autre classes
        private 				JPanel 					    statusbar;
        private 				JLabel 					    status;
        private 				GridBagConstraints 		    c;
        private 				String 					    labels[] = {"          RMC    ", "          France Info          ", "          FunRadio    ", "          Skyrock    ", "          Radiox    ", "          Radioy    " };
        private 				String 					    labelsFav[] = {"WebRadios(par défaut)", "Mes Radios Favorites" };
        private 				DefaultComboBoxModel 	    model;
        private 				JComboBox			        comboBox;
        private 				JList 					    liste;
        private 				JScrollPane                 scrollPane;
        private 				JButton 				    boutonConnexion;
        private 				JButton 				    boutonExit;
        private 				JFileChooser 			    chooser;
        private 				FileNameExtensionFilter     filter;
        private 				JMenuBar 					menubar;
        private 				JMenu 						menuFichier;
        private 				JMenu 						menuPreferences;
        private 				JMenu 						menuAide;
        private 				JMenuItem 					itemConnect;
        private 				JMenuItem				    itemExit;
        private 				JMenuItem	 				itemCfg;
        private 				JMenuItem		 			itemHelp;
        private 				JMenuItem				 	itemBlog;
        private 				JMenuItem 				 	itemInfo;
        private 	Object 		xpa;
        private				    String chemin;
        private 				JProgressBar bar;  // private STATIC pour utiliser JProgressBar dans d'autre classes
        int 					min = 0;
        int 					max = 100;
        int 					i; 
        int						j;
     
     
     
     
     
     
        @SuppressWarnings("deprecation")
    	public FenetrePrincipale() {
     
     
     
        	            super("PTI JAVA 2010 BENOIT POURVILLE");
            panneau 			= 				new JPanel(new GridBagLayout());
     
            statusbar		    = 				new JPanel(new GridBagLayout());
            status 				= 				new JLabel("PTI 2010 IGD BENOIT POURVILLE");
            c 					= 				new GridBagConstraints();
            model 				= 				new DefaultComboBoxModel(labels);
            comboBox		    = 				new JComboBox(labelsFav);
            liste 				= 				new JList(model);
            scrollPane 			= 				new JScrollPane(liste);
            boutonConnexion     =			    new JButton("Connexion!");
            boutonExit		    =			    new JButton("Quitter");     
            chooser 			= 				new JFileChooser();
     
            filter 				= 				new FileNameExtensionFilter("Fichiers Exécutables", new String[] {"exe"}); // Filtre du JFC pour n'accepter que les executables
            menubar			    = 				new JMenuBar();
            menuFichier 		= 				new JMenu("Fichier");
            menuPreferences 	= 				new JMenu("Préférences");
            menuAide 			= 				new JMenu("?");
     
            itemConnect 		= 				new JMenuItem("Se Connecter");
            itemExit 			= 				new JMenuItem("Quitter");
            itemCfg 			= 				new JMenuItem("Configurer...");
            itemHelp 			= 				new JMenuItem("Aide");
            itemBlog 			= 				new JMenuItem("Visiter le Blog...");
            itemInfo 			= 				new JMenuItem("A propos...");
     
            bar 				= 				new JProgressBar();
     
     
            bar.setMinimum(min);
            bar.setMaximum(max);
            bar.setBorderPainted(true);
     
            c.weightx = 1.0D;
            c.weighty = 0.5D;
            c.anchor = 14;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 4;
            c.gridy = 3;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(bar, c);
     
     
            boutonConnexion.setActionCommand("boutonConnexion"); 
            itemConnect.setActionCommand("boutonConnexion");
     
            itemCfg.setActionCommand("Configurer");
     
     
            boutonConnexion.setForeground(Color.WHITE);
            boutonConnexion.setBackground(Color.BLACK);
            boutonConnexion.addMouseListener(new MouseAdapter() {
     
     
     
                public void mouseEntered(MouseEvent e)
                {
                    boutonConnexion.setForeground(Color.BLACK);
                    boutonConnexion.setBackground(Color.GRAY);
                }
            });
            boutonConnexion.addMouseListener(new MouseAdapter() {
     
            	public void mouseExited(MouseEvent e)
                {
                    boutonConnexion.setForeground(Color.GRAY);
                    boutonConnexion.setBackground(Color.BLACK);
                }
            });
     
     
            boutonExit.setBackground(Color.BLACK);
            boutonExit.setForeground(Color.WHITE);
            boutonExit.addActionListener(new Exit());
            boutonExit.addMouseListener(new MouseAdapter() {
     
                public void mouseEntered(MouseEvent e)
                {
                    boutonExit.setForeground(Color.BLACK);
                    boutonExit.setBackground(Color.GRAY);
                }
            });
            boutonExit.addMouseListener(new MouseAdapter() {  // bouton exit changement couleur au survolage
     
                public void mouseExited(MouseEvent e)
                {
                    boutonExit.setForeground(Color.GRAY);
                    boutonExit.setBackground(Color.BLACK);
                }
            });
     
            panneau.add(statusbar);
            statusbar.add(status);
     
     
            c.weightx = 1.0D;
            c.weighty = 0.0D;
            c.anchor = 13;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 2;
            c.gridy = 1;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(comboBox, c);
     
     
            comboBox.addActionListener(new ActionListener() {
     
                public void actionPerformed(ActionEvent arg0)
                {
                    System.out.println("Liste radio par defaut / Liste utilisateur");
                    comboBox.getItemListeners();
                }
            });
     
            // Commentaires a refaire sur la position des boutons
            c.weightx = 1.0D;
            c.weighty = 0.0D;
            c.anchor = 10;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 2;
            c.gridy = 2;
            c.insets = new Insets(10, 10, 10, 10);
     
            ListEx.booklist.setBackground(Color.GRAY);
            panneau.add(ListEx.booklist, c); // Ajout de la JList issue de la classe ListEx
     
     
            c.weightx = 1.0D;
            c.weighty = 0.0D;
            c.anchor = 18;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 1;
            c.gridy = 1;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(boutonConnexion, c);
     
     
     
     
     
     
            // ON commence par lire le fichier XML de config meme si il n'est pas encore CONFIG
     
        	SAXBuilder sxb = new SAXBuilder();
            Document document = null;
            try
            {
                document = sxb.build(new File("config.xml"));
                org.jdom.Element racine = document.getRootElement();
                XPath xpa = null;
                xpa = XPath.newInstance("//string");
                chemin = xpa.valueOf(racine);
            }
            catch(JDOMException e1)
            {
                e1.printStackTrace();
            }
            catch(IOException e1)
            {
                e1.printStackTrace();
            }
     
     
            System.out.println("DEBUG    :  ");
            System.out.println(chemin);
            System.out.println(Radio.rmc);
     
     
     
           //////////////// 
     
     
     
            c.weightx = 1.0D;
            c.weighty = 0.5D;
            c.anchor = 14;
            c.gridheight = 1;
            c.gridwidth = 1;
            c.gridx = 4;
            c.gridy = 4;
            c.insets = new Insets(10, 10, 10, 10);
            panneau.add(boutonExit, c);
     
     
     
            itemBlog.addActionListener(new Blog());
            itemHelp.addActionListener(new Help());
            itemInfo.addActionListener(new Info());
            itemExit.addActionListener(new Exit());
     
     
            boutonConnexion.addActionListener(this);
     
     
            itemCfg.addActionListener(this);
            itemConnect.addActionListener(this); 
     
            Container contentPane = getContentPane();
            contentPane.add(scrollPane, "Center");
            scrollPane.createVerticalScrollBar();
     
     
            panneau.add(scrollPane);
            panneau.add(menubar);
     
     
            menubar.add(menuFichier);
            menubar.add(menuPreferences);
            menubar.add(menuAide);
            menuFichier.add(itemConnect);
            menuFichier.addSeparator();
            menuFichier.add(itemExit);
            menuPreferences.add(itemCfg);
            menuAide.add(itemHelp);
            menuAide.add(itemBlog);
            menuAide.addSeparator();
            menuAide.add(itemInfo);
     
     
            chooser.setFileFilter(filter); // filtre sur le JFileChooser ( "exe" )
            setLayout(new BorderLayout(9, 3));
     
            add(panneau, "Center");
            add(statusbar, "South");
            setResizable(false); // interdiction de redimmentioner la fenêtre
            setVisible(true); 
            panneau.setBackground(Color.darkGray); // Fond gris foncé..
            setSize(800, 400); // taille fenêtre 600x400 pxl
            setJMenuBar(menubar);  
            show();
        }
     
         @SuppressWarnings("deprecation")
    	public void actionPerformed(ActionEvent aActionEvent) {
     
        		String action = aActionEvent.getActionCommand();
     
        		    if(action.equals("Configurer")) // Fonction Configuration
        		{
        			if(this.chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
        			{
        				chemin = (chooser.getSelectedFile().getAbsolutePath());
        				System.out.println(chemin);
        			}
     
     
        			xpa = null;
        	        try
        	        {
        	            xpa = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("config.xml")));  // Fonction pour creer fichier xml
        	            ((XMLEncoder) xpa).writeObject(chemin);
        	            System.out.println(xpa);
     
        	        }
        	        catch(FileNotFoundException e1)
        	        {
        	            e1.printStackTrace();
        	        }
     
        	        ((XMLEncoder) xpa).close();
     
        		}
     
        		if(action.equals("boutonConnexion")&&(chemin==null)) // Si le fichier Config est vierge ouverture de la fenetre de config
     
        		{
        			System.out.println("Aucune configuration trouvée...");
        			System.out.println(chemin);
     
        			JOptionPane pane = new JOptionPane(); 
        			int option = JOptionPane.showConfirmDialog(null, "Veuillez Configurer votre Lecteur Multimedia", "INFORMATION", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        			pane.show();
     
        			if(option == JOptionPane.OK_OPTION)
        			{
        				System.out.println("Go configurer");
     
        				this.chooser.showOpenDialog(this);
     
        				}
        			else 
        				System.out.println("Retour au menu principal");
     
        		}
     
        		if(action.equals("boutonConnexion")&&(chemin!=null)) // Fichier configuration OK : Execution du Lecteur avec la commande propre a la Station
     
        		{
        			for (int j=0; j<=100; j++) // Fonction de la progress Bar
        			{
     
        			bar.setValue(j);
     
        			}
     
        			try {
    					Thread.sleep(100);
    				} catch (InterruptedException e) {
     
    					e.printStackTrace();
    				} 
        		}
     
        				try {
        					String rmc = Radio.rmc;
    						Runtime.getRuntime().exec(new String[] {chemin } );
    					} catch (IOException e) {
     
    						e.printStackTrace();
    					} 
     
        			    System.out.println(chemin);
        			    System.out.println("Debug 2 : radio :");
     
     
        			}						               //	"http://pendora.fr.nf:8000/listen.pls"
    La classe ListEx :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
         public class ListEx extends JPanel { 
     
        	    /**
                     * 
                     */
    		private static final long serialVersionUID = 1L;
     
    			private BookEntry books[] = {
        	    		new BookEntry("ITEM A", "shortIcon.jpg"),
        	    		new BookEntry("ITEM B", "longIcon.jpg")
     
        	    };
     
        	    private JList booklist = new JList(books);
     
        	    public ListEx() {
        	    	setLayout(new BorderLayout());
        	    	JButton button = new JButton("Connect");
        	    	button.addActionListener(new PrintListener());
     
        	    	booklist = new JList(books);
        	    	booklist.setCellRenderer(new BookCellRenderer());
        	    	booklist.setVisibleRowCount(4);
        	    	JScrollPane panez = new JScrollPane(booklist);
     
        	    	add(panez, BorderLayout.NORTH);
        	    	add(button, BorderLayout.SOUTH);
     
        	    }
     
        	    class PrintListener implements ActionListener {
        	    	public void actionPerformed(ActionEvent e) {
        	    		int selected[] = booklist.getSelectedIndices();
        	    		System.out.println("Selected Elements :  ");
     
        	    		for (int f = 0; i < selected.length; i++) {
        	    			BookEntry element = (BookEntry) booklist.getModel().getElementAt(selected[i]);
        	    			System.out.println("   " + element.getTitle());
     
        	    			}
        	    		}
        	    	}
        	    }
     
        	    class BookEntry {
        	    	private final String title;
     
        	    	private final String imagePath;
     
        	    	private ImageIcon image;
     
        	    	public BookEntry(String title, String imagePath) {
        	    		this.title = title;
        	    		this.imagePath = imagePath;
     
        	    	}
     
    				public String getTitle() {
    					// TODO Auto-generated method stub
    					return title;
    				}
    				public ImageIcon getImage() {
    					if(image == null) {
    						image = new ImageIcon(imagePath);
    					}
     
        	    	return image;
        	    }
     
        	    public String toString() {
        	    	return title;
        	    }
        	}
     
        	@SuppressWarnings("serial")
    		static class BookCellRenderer extends JLabel implements ListCellRenderer {
     
        		private final Color HIGHLIGHT_COLOR = new Color(0, 0, 128);
     
        		public BookCellRenderer() {
        			setOpaque(true);
        			setIconTextGap(12);
        		}
     
        		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        			BookEntry entry = (BookEntry) value;
        			setText(entry.getTitle());
        			setIcon(entry.getImage());
        			if(isSelected) {
        				setBackground(HIGHLIGHT_COLOR);
        				setForeground(Color.white);
        			} else {
        				setBackground(Color.white);
        				setForeground(Color.black);
        			}
        			return this;
        			}
        	}
    }
    Merci, bonne journée

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 12/09/2005, 19h23
  2. déplacé icone sur bureau
    Par suiss dans le forum Autres Logiciels
    Réponses: 12
    Dernier message: 02/09/2005, 18h08
  3. [MFC] mettre des icones sur un CTreeCtrl
    Par Toutouffe dans le forum MFC
    Réponses: 3
    Dernier message: 30/11/2004, 17h11
  4. [Jlist] Clic sur jlist
    Par bibx dans le forum Composants
    Réponses: 6
    Dernier message: 07/05/2004, 10h19
  5. [icone]Comment appliquer une icone sur le.exe
    Par JavaLeDirePartout dans le forum JBuilder
    Réponses: 7
    Dernier message: 24/07/2003, 17h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo