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
| // LISTE DES IMPORTS
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
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.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
public class FenetrePrincipale extends JFrame implements ActionListener {
// private JFrame frame = new JFrame();
private JPanel panneau = new JPanel(new GridBagLayout());
private GridBagConstraints c = new GridBagConstraints();
private String labels[] = { "radio1", "radio2", "radio3", "radio4" };
//private DefaultComboBoxModel model = new DefaultComboBoxModel(labels);
private JList liste = new JList();
private JButton boutonExec = new JButton("Connexion");
private JButton boutonExit = new JButton("Quitter");
private JTextField textChemin = new JTextField(50);
private JFileChooser chooser = new JFileChooser();
private FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers Exécutables", "exe");
// MENU
private JMenuBar menubar = new JMenuBar();
private JMenu menuFichier = new JMenu("Fichier");
private JMenu menuPreferences = new JMenu("Préférences");
private JMenu menuAide = new JMenu("?");
// SOUS MENUS
private JMenuItem itemConnect = new JMenuItem("Se Connecter");
private JMenuItem itemExit = new JMenuItem("Quitter");
private JMenuItem itemCfg = new JMenuItem("Configurer...");
private JMenuItem itemHelp = new JMenuItem("Aide");
private JMenuItem itemBlog = new JMenuItem("Visiter le Blog...");
private JMenuItem itemInfo = new JMenuItem("A propos...");
public FenetrePrincipale() {
super("pendoRa Mix Radio 1.1");
this.boutonExec.setActionCommand("boutonOK");
this.itemCfg.setActionCommand("Configurer");
this.itemConnect.setActionCommand("Connexion");
// Mise en place des écouteurs
// this.liste.addActionListener(new ListeRadio());
// Boutons
this.boutonExec.addActionListener(this);
this.boutonExit.addActionListener(new Exit());
// Placement du bouton Exit
this.c.weightx=1;
this.c.weighty=0.5;
this.c.anchor=GridBagConstraints.LAST_LINE_START;
this.c.gridheight=1;
this.c.gridwidth=GridBagConstraints.REMAINDER;
this.c.gridx=0;
this.c.gridy=1;
this.c.insets=new Insets(0, 10, 0, 0);
this.panneau.add(this.boutonExit, c);
// Placement du bouton de Connexion
this.c.weightx=1;
this.c.weighty=0;
this.c.anchor=GridBagConstraints.LINE_START;
this.c.gridheight=1;
this.c.gridwidth=GridBagConstraints.REMAINDER;
this.c.gridx=0;
this.c.gridy=2;
this.c.insets=new Insets(30, 10, 0, 0);
this.panneau.add(this.boutonExec, c);
// Menu
this.itemBlog.addActionListener(new Blog());
this.itemHelp.addActionListener(new Help());
this.itemInfo.addActionListener(new Info());
this.itemExit.addActionListener(new Exit());
this.itemCfg.addActionListener(this);
this.itemConnect.addActionListener(this);
// Ajout de la liste
this.panneau.add(this.liste);
// Ajout des boutons
this.panneau.add(this.textChemin);
//textChemin.setVisible(false);
//this.panneau.add(this.boutonExec);
//this.panneau.add(this.boutonExit);
// Ajout du menuBar
this.panneau.add(this.menubar);
// Ajout de sous-menus
menubar.add(this.menuFichier);
menubar.add(this.menuPreferences);
menubar.add(this.menuAide);
// Ajout des Menu Items
// Menu Fichier
menuFichier.add(this.itemConnect);
menuFichier.addSeparator();
menuFichier.add(this.itemExit);
// Menu Préférences
menuPreferences.add(this.itemCfg);
// Menu Aide (?)
menuAide.add(this.itemHelp);
menuAide.add(this.itemBlog);
menuAide.addSeparator();
menuAide.add(this.itemInfo);
// Filtre du JFileChooser
this.chooser.setFileFilter(filter);
//Hide le chemin d'accès
textChemin.setVisible(false);
// Layout
this.setLayout(new BorderLayout(9, 3));
this.add(this.panneau, BorderLayout.CENTER);
// La fenetre...
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.panneau.setBackground(Color.RED);
this.setSize(600, 400);
this.setJMenuBar(menubar);
this.show();
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent aActionEvent) {
String action = aActionEvent.getActionCommand();
if(action.equals("Configurer"))
{
if(this.chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
{
this.textChemin.setText(this.chooser.getSelectedFile().getAbsolutePath());
}
}
if(action.equals("boutonOK"))
{
try
{
Runtime.getRuntime().exec(new String[] {this.textChemin.getText(), "http://pendora.fr.nf:8000/listen.pls" } );
// test avec fichier audio "C:\\Users\\pendoRa\\Music\\son\\LIFE.mp3"
}
catch (IOException aIOException)
{
JOptionPane.showMessageDialog(this, aIOException.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
}
}
if(action.equals("Connexion"))
{
try
{
Runtime.getRuntime().exec(new String[] {this.textChemin.getText(), "http://pendora.fr.nf:8000/listen.pls" }) ;
// test avec fichier audio "C:\\Users\\pendoRa\\Music\\son\\LIFE.mp3"
}
catch (IOException aIOException)
{
JOptionPane.showMessageDialog(this, aIOException.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
}
}
}
public static void main(String[] args) {
new FenetrePrincipale();
}
} |
Partager