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
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
import metier.*;
public class MainWindowVersionUn extends JFrame implements ActionListener, ItemListener {
int width=1400;int height=480;
String presentationTexteDepart="";
String strTempDepart="";
String presentationTexteArrivee="";
String strTempArrivee="";
String presentationTexteTypeVoyageurs="";
String strTempTypeVoyageurs="";
String presentationTexteTypeTransport="";
String strTempTypeTransport="";
String presentationTexteJoursSemaine="";
String strTempJoursSemaine="";
String presentationBilletAllerSimple="";
String presentationBilletAllerRetour="";
String presentationBilletCarteJeune="";
String presentationBilletCarteGrandVoyageurs="";
String presentationBilletReducPro="";
String presentationBilletReducLoisirs="";
String resultTotale=presentationTexteDepart+strTempDepart+
presentationTexteArrivee+strTempArrivee+
presentationTexteTypeVoyageurs+strTempTypeVoyageurs+
presentationTexteTypeTransport+strTempTypeTransport+
presentationTexteJoursSemaine+strTempJoursSemaine+
presentationBilletAllerRetour+presentationBilletAllerSimple+
presentationBilletCarteJeune+presentationBilletCarteGrandVoyageurs+
presentationBilletReducPro+presentationBilletReducLoisirs;
GridLayout disposition = new GridLayout(9, 2);
//------------------- Liste d'items de la liste
private final static String[] TAB_VILLES =
{ "Marseille", "Nice", "Bordeaux", "Brest", "Toulouse", "Toulon", "Strasbourg","Paris"};
Vector<Ville> tableauVille=new Vector<Ville>();
Ville marseille=new Ville("Marseille",70,20);
Ville nice=new Ville("Nice",10,10);
Ville bordeaux=new Ville("Bordeaux",40,60);
Ville brest=new Ville("Brest",10,110);
Ville toulouse=new Ville("Toulouse",30,30);
Ville toulon=new Ville("Toulon",10,110);
Ville strasbourg=new Ville("Strasbourg",11,14);
Ville paris=new Ville("Paris",80,80);
private final static String[] TAB_SEMAINE =
{ "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"};
private final static String[] TAB_TYPES_TRANSPORT =
{ "MiniBus", "BusNormal", "TGV", "TER", "TIC"};
private JPanel panelStatusBar=new JPanel();
private JPanel panelReservations=new JPanel();
private JPanel panelAdministrateur=new JPanel();
private JLabel lbTauxTVE=new JLabel("TVE : ");
private JTextField textFieldTVE=new JTextField(20);
private JLabel lbChoixVilleDepart=new JLabel("Choisir votre ville de depart");
private JComboBox<Ville> comboBoxVilleDepart=new JComboBox<>(tableauVille);
private JLabel lbChoixVilleArrivee=new JLabel("Choisir votre ville d'arrivée");
private JComboBox<Ville> comboBoxVilleArrivee=new JComboBox<>(tableauVille);
private JLabel lbChoixTypeTransport=new JLabel("Quel type moyen de transport allez-vous prendre ?");
private JComboBox comboBoxTypeTransport=new JComboBox(TAB_TYPES_TRANSPORT);
private JLabel lbChoixJoursSemaine=new JLabel("Quels est le jours de la semaine ?");
private JComboBox comboBoxJoursSemaine=new JComboBox(TAB_SEMAINE);
private JPanel panelAllerRetour=new JPanel();
private ButtonGroup buttonGroupAllerRetour=new ButtonGroup();
private JLabel lbChoixAllerRetour=new JLabel("est-ce que ce un aller-retour ou un aller-simple");
private JRadioButton radioButtonAllerRetour=new JRadioButton("Aller Retour");
private JRadioButton radioButtonAllerSimple=new JRadioButton("Aller Simple");
private JPanel panelTypeVoyageurs=new JPanel();
private ButtonGroup buttonGroupTypeVoyageurs=new ButtonGroup();
private JLabel lbChoixTypeVoyageurs=new JLabel("Quel type de voyageurs etes vous ?");
private JRadioButton radioButtonCarteJeune=new JRadioButton("Carte Jeune");
private JRadioButton radioButtonCarteGrandVoyageurs=new JRadioButton("Carte Grand Voyageurs");
private JPanel panelCarteReduc=new JPanel();
private ButtonGroup buttonGroupCarteReduc=new ButtonGroup();
private JLabel lbChoixCarteReduc=new JLabel("Choisir votre carte de reduction");
private JRadioButton radioButtonReducLoisirs=new JRadioButton("Loisirs");
private JRadioButton radioButtonReducPro=new JRadioButton("Professionnels");
private JLabel lbPrix=new JLabel("Prix");
private JTextField resultPrix=new JTextField(20);
private JTextArea textAreaResult=new JTextArea(300, 55);
JScrollPane spAreaResult = new JScrollPane(textAreaResult);
private JButton bouton = new JButton("Go");
private JButton bouton2 = new JButton("Stop");
public MainWindowVersionUn(String title){
super(title);
this.setSize(width,height);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
bouton.addActionListener(new BoutonListener());
bouton2.addActionListener(new Bouton2Listener());
gestionDisposition();
gestionActionListener();
gestionAffichage();
ajoutValeurComboBox();
}
public void ajoutValeurComboBox(){
comboBoxVilleDepart.addItem(marseille);
comboBoxVilleDepart.addItem(nice);
comboBoxVilleDepart.addItem(brest);
comboBoxVilleDepart.addItem(toulouse);
comboBoxVilleDepart.addItem(bordeaux);
comboBoxVilleDepart.addItem(toulon);
comboBoxVilleDepart.addItem(strasbourg);
comboBoxVilleDepart.addItem(paris);
comboBoxVilleArrivee.addItem(marseille);
comboBoxVilleArrivee.addItem(nice);
comboBoxVilleArrivee.addItem(brest);
comboBoxVilleArrivee.addItem(toulouse);
comboBoxVilleArrivee.addItem(bordeaux);
comboBoxVilleArrivee.addItem(toulon);
comboBoxVilleArrivee.addItem(strasbourg);
comboBoxVilleArrivee.addItem(paris);
}
public void gestionDisposition(){
panelReservations.setLayout(disposition);
panelReservations.add(lbChoixVilleDepart);panelReservations.add(comboBoxVilleDepart);
panelReservations.add(lbChoixVilleArrivee);panelReservations.add(comboBoxVilleArrivee);
panelReservations.add(lbChoixTypeTransport);panelReservations.add(comboBoxTypeTransport);
panelReservations.add(lbChoixJoursSemaine);panelReservations.add(comboBoxJoursSemaine);
panelReservations.add(lbChoixCarteReduc);panelReservations.add(panelCarteReduc);
buttonGroupCarteReduc.add(radioButtonReducLoisirs);buttonGroupCarteReduc.add(radioButtonReducPro);
panelCarteReduc.add(radioButtonReducLoisirs);panelCarteReduc.add(radioButtonReducPro);
panelReservations.add(lbChoixTypeVoyageurs);panelReservations.add(panelTypeVoyageurs);
panelTypeVoyageurs.add(radioButtonCarteJeune);panelTypeVoyageurs.add(radioButtonCarteGrandVoyageurs);
buttonGroupTypeVoyageurs.add(radioButtonCarteJeune);buttonGroupTypeVoyageurs.add(radioButtonCarteGrandVoyageurs);
panelReservations.add(lbChoixAllerRetour);panelReservations.add(panelAllerRetour);
panelAllerRetour.add(radioButtonAllerRetour);panelAllerRetour.add(radioButtonAllerSimple);
panelReservations.add(lbPrix);panelReservations.add(resultPrix);
panelAdministrateur.add(lbTauxTVE);panelAdministrateur.add(textFieldTVE);
panelReservations.add(bouton);panelReservations.add(bouton2);
add(panelAdministrateur,BorderLayout.WEST);
add(panelReservations,BorderLayout.EAST);
add(spAreaResult,BorderLayout.CENTER);
add(panelStatusBar, BorderLayout.SOUTH );
}
public void gestionActionListener(){
comboBoxVilleDepart.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
presentationTexteDepart="Départ de : ";
textAreaResult.append(presentationTexteDepart);
strTempDepart=comboBoxVilleDepart.getSelectedItem().toString();
textAreaResult.append(strTempDepart+'\n');
}});
comboBoxVilleArrivee.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
presentationTexteArrivee="Arrivée de : ";
textAreaResult.append(presentationTexteArrivee);
strTempArrivee=comboBoxVilleArrivee.getSelectedItem().toString();
textAreaResult.append(strTempArrivee+'\n');
}});
comboBoxTypeTransport.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
presentationTexteTypeTransport="Type de Transport : ";
textAreaResult.append(presentationTexteTypeTransport);
strTempTypeTransport=comboBoxTypeTransport.getSelectedItem().toString();
textAreaResult.append(strTempTypeTransport+'\n');
}});
comboBoxJoursSemaine.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
presentationTexteJoursSemaine="Jours de la semaine : ";
textAreaResult.append(presentationTexteJoursSemaine);
strTempJoursSemaine=comboBoxJoursSemaine.getSelectedItem().toString();
textAreaResult.append(strTempJoursSemaine+'\n');
}});
radioButtonAllerRetour.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
presentationBilletAllerRetour="Aller-Retour : ";
presentationBilletAllerSimple="Aller-Simple : ";
if(radioButtonAllerRetour.isSelected()){
textAreaResult.append(presentationBilletAllerRetour);
textAreaResult.append("Oui"+'\n');}
else {
textAreaResult.append(presentationBilletAllerSimple);
textAreaResult.append("Non"+'\n');}
}
});
radioButtonAllerSimple.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
presentationBilletAllerRetour="Aller-Retour : ";
presentationBilletAllerSimple="Aller-Simple : ";
if(radioButtonAllerSimple.isSelected()){
textAreaResult.append(presentationBilletAllerSimple);
textAreaResult.append("Non"+'\n');}
else {
textAreaResult.append(presentationBilletAllerRetour);
textAreaResult.append("Oui"+'\n');}
}
});
radioButtonReducLoisirs.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
presentationBilletReducPro="Reduction Pro : ";
presentationBilletReducLoisirs="Reduction Loisirs : ";
if(radioButtonReducLoisirs.isSelected()){
textAreaResult.append(presentationBilletReducLoisirs);
textAreaResult.append("Oui"+'\n');}
else {
textAreaResult.append(presentationBilletReducPro);
textAreaResult.append("Oui"+'\n');}
}
});
radioButtonReducPro.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
presentationBilletReducPro="Reduction Pro : ";
presentationBilletReducLoisirs="Reduction Loisirs : ";
if(radioButtonReducPro.isSelected()){
textAreaResult.append(presentationBilletReducPro);
textAreaResult.append("Non"+'\n');}
else {
textAreaResult.append(presentationBilletReducLoisirs);
textAreaResult.append("Oui"+'\n');}
}
});
radioButtonCarteJeune.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
presentationBilletCarteJeune="Carte Jeune : ";
presentationBilletCarteGrandVoyageurs="Carte Grand Voyageurs : ";
if(radioButtonCarteJeune.isSelected()){
textAreaResult.append(presentationBilletCarteJeune);
textAreaResult.append("Oui"+'\n');}
else {
textAreaResult.append(presentationBilletCarteGrandVoyageurs);
textAreaResult.append("Oui"+'\n');}
}
});
radioButtonCarteGrandVoyageurs.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
presentationBilletCarteJeune="Carte Jeune : ";
presentationBilletCarteGrandVoyageurs="Carte Grand Voyageurs : ";
if(radioButtonCarteGrandVoyageurs.isSelected()){
textAreaResult.append(presentationBilletCarteGrandVoyageurs);
textAreaResult.append("Non"+'\n');}
else {
textAreaResult.append(presentationBilletCarteJeune);
textAreaResult.append("Oui"+'\n');}
}
});
}
public void gestionAffichage(){
textAreaResult.setText(resultTotale);
}
public static void main(String[] args) {new MainWindowVersionUn("Systeme de Reservation de transport");}
@Override
public void actionPerformed(ActionEvent e) {
}
@Override
public void itemStateChanged(ItemEvent e) {
}
public class BoutonListener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
Ville VilleDepart = (Ville) comboBoxVilleDepart.getSelectedItem();
Ville VilleArrivee = (Ville) comboBoxVilleArrivee.getSelectedItem();
int contentsVilleDepart = comboBoxVilleDepart.getSelectedIndex();
int contentsVilleArrivee = comboBoxVilleArrivee.getSelectedIndex();
System.out.println(contentsVilleDepart+" "+contentsVilleArrivee);
if(contentsVilleDepart !=contentsVilleArrivee) {
Trajet trajetUn
=new Trajet(
tableauVille.set(contentsVilleDepart,VilleDepart),
tableauVille.set(contentsVilleArrivee,VilleArrivee));
System.out.println("Distance : "+trajetUn.getDistance(VilleDepart,VilleArrivee));
System.out.println("Selected index=" + comboBoxVilleDepart.getSelectedIndex()
+ " Selected item=" + (Ville) comboBoxVilleDepart.getSelectedItem());
System.out.println("Selected index=" + comboBoxVilleArrivee.getSelectedIndex()
+ " Selected item=" + (Ville) comboBoxVilleArrivee.getSelectedItem());
}
bouton.setEnabled(false);
bouton2.setEnabled(true);
if(bouton.isSelected())
gestionActionListener();
}
}
public class Bouton2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
bouton.setEnabled(true);
bouton2.setEnabled(false);
}
}
} |
Partager