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 :

Petit souci avec les Vector


Sujet :

Java

  1. #1
    Invité
    Invité(e)
    Par défaut Petit souci avec les Vector
    Bonjour, je suis un niveau intermédiaire en java et j'ai un souci d'index dans un vector .

    l'objet de mon exo est simple faire une réservation pour un billet de transport !
    - on peut choisir le jour de la semaine, une réduction lié à la distance du trajet si on voyage beaucoup, une destination de départ et d'arrivée et le type de transport (bus, train ect.)
    -voici le sujet complet : malefis.u-strasbg.fr/site/Enseignement/POO/TP4/sujet_tp4.pdf

    mon code source complet :

    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
     
    public class Ville{
    	private String nom;
    	private double coordX;
    	private double coordY;
    	public Ville(String nom, double coordX, double coordY) {
    		super();
    		this.nom = nom;
    		this.coordX = coordX;
    		this.coordY = coordY;
    	}
    	public String getNom() {
    		return nom;
    	}
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
    	public double getCoordX() {
    		return coordX;
    	}
    	public void setCoordX(double coordX) {this.coordX = coordX;}
    	public double getCoordY() {return coordY;}
    	public void setCoordY(double coordY) {this.coordY = coordY;}
    	public double getDistance(Ville ville1,Ville ville2){
    		double coordVille1X=ville1.getCoordX();
    		double coordVille1Y=ville1.getCoordY();
    		double coordVille2X=ville2.getCoordX();
    		double coordVille2Y=ville2.getCoordY();
    		double distance =
    				Math.sqrt((coordVille2X-coordVille1X)*(coordVille2X-coordVille1X)+
    					 (coordVille2Y-coordVille1Y)*(coordVille2Y-coordVille1Y));
    		return distance;
    	}
     
    }
    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
     
     
    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 comboBoxVilleDepart=new JComboBox(tableauVille);
    	private JLabel lbChoixVilleArrivee=new JLabel("Choisir votre ville d'arrivée");
    	private JComboBox 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.getNom());
    		comboBoxVilleDepart.addItem(nice.getNom());
    		comboBoxVilleDepart.addItem(brest.getNom());
    		comboBoxVilleDepart.addItem(toulouse.getNom());
    		comboBoxVilleDepart.addItem(bordeaux.getNom());
    		comboBoxVilleDepart.addItem(toulon.getNom());
    		comboBoxVilleDepart.addItem(strasbourg.getNom());
    		comboBoxVilleDepart.addItem(paris.getNom());
    		comboBoxVilleArrivee.addItem(marseille.getNom());
    		comboBoxVilleArrivee.addItem(nice.getNom());
    		comboBoxVilleArrivee.addItem(brest.getNom());
    		comboBoxVilleArrivee.addItem(toulouse.getNom());
    		comboBoxVilleArrivee.addItem(bordeaux.getNom());
    		comboBoxVilleArrivee.addItem(toulon.getNom());
    		comboBoxVilleArrivee.addItem(strasbourg.getNom());
    		comboBoxVilleArrivee.addItem(paris.getNom());
    	}
    	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) {
    		    	 int contentsVilleDepart = comboBoxVilleDepart.getSelectedIndex();
    		    	 int contentsVilleArrivee = comboBoxVilleArrivee.getSelectedIndex();
    		    	 System.out.println(contentsVilleDepart+" "+contentsVilleArrivee);
    		    	 if(contentsVilleDepart !=contentsVilleArrivee) {
    		    		 Trajet trajetUn
    		    		 =new Trajet(
    		    				 tableauVille.get(contentsVilleDepart),
    		    				 tableauVille.get(contentsVilleArrivee));
    		    		 System.out.println("Distance : "+trajetUn.getDistance(marseille,nice));
    		    	        System.out.println("Selected index=" + comboBoxVilleDepart.getSelectedIndex()
    		    	                + " Selected item=" + comboBoxVilleDepart.getSelectedItem());
    		    	        System.out.println("Selected index=" + comboBoxVilleArrivee.getSelectedIndex()
    		    	                + " Selected item=" + 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);
    		    }  
    		  }  
     
     
    }
    l'objet de mon souci se situe ici :

    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
     
     
    public void actionPerformed(ActionEvent arg0) {
    		    	 int contentsVilleDepart = comboBoxVilleDepart.getSelectedIndex();
    		    	 int contentsVilleArrivee = comboBoxVilleArrivee.getSelectedIndex();
    		    	 System.out.println(contentsVilleDepart+" "+contentsVilleArrivee);
    		    	 if(contentsVilleDepart !=contentsVilleArrivee) {
    		    		 Trajet trajetUn
    		    		 =new Trajet(
    		    				 tableauVille.get(contentsVilleDepart),
    		    				 tableauVille.get(contentsVilleArrivee));
    		    		 System.out.println("Distance : "+trajetUn.getDistance(marseille,nice));
    		    	        System.out.println("Selected index=" + comboBoxVilleDepart.getSelectedIndex()
    		    	                + " Selected item=" + comboBoxVilleDepart.getSelectedItem());
    		    	        System.out.println("Selected index=" + comboBoxVilleArrivee.getSelectedIndex()
    		    	                + " Selected item=" + comboBoxVilleArrivee.getSelectedItem());
    		    	 }
    voici le code erreur :

    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
     
    0 -1
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to metier.Ville
    	at IHM.MainWindowVersionUn$BoutonListener.actionPerformed(MainWindowVersionUn.java:284)
    	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    	at java.awt.Component.processMouseEvent(Component.java:6516)
    	at javax.swing.JComponent.processMouseEvent(JComponent.java:3311)
    	at java.awt.Component.processEvent(Component.java:6281)
    	at java.awt.Container.processEvent(Container.java:2229)
    	at java.awt.Component.dispatchEventImpl(Component.java:4872)
    	at java.awt.Container.dispatchEventImpl(Container.java:2287)
    	at java.awt.Component.dispatchEvent(Component.java:4698)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    	at java.awt.Container.dispatchEventImpl(Container.java:2273)
    	at java.awt.Window.dispatchEventImpl(Window.java:2719)
    	at java.awt.Component.dispatchEvent(Component.java:4698)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
    	at java.awt.EventQueue.access$200(EventQueue.java:103)
    	at java.awt.EventQueue$3.run(EventQueue.java:694)
    	at java.awt.EventQueue$3.run(EventQueue.java:692)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    	at java.awt.EventQueue$4.run(EventQueue.java:708)
    	at java.awt.EventQueue$4.run(EventQueue.java:706)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
    ma question est simple comment recuperer l'objet selectionné provenant des JComboBox pour renvoyer la distance entre les 2 villes

    merci à tous pour la reponse

    BlackAllSun
    Dernière modification par joel.drigo ; 30/08/2014 à 18h04. Motif: Séparation code en 2 classes disctintes

  2. #2
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Tu as écrit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Vector<Ville> tableauVille=new Vector<Ville>();
    private JComboBox comboBoxVilleDepart=new JComboBox(tableauVille);
    Puis tu ajoutes dans ta JComboBox les valeurs comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    comboBoxVilleDepart.addItem(marseille.getNom());
    ...
    Donc tu mets des String dans ta combo (getNom() retourne un String).

    Puis quand tu écris :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Trajet trajetUn=new Trajet(
    		    				 tableauVille.get(contentsVilleDepart),
    		    				 tableauVille.get(contentsVilleArrivee));
    Tu ne nous as pas fourni le code de la classe Trajet, mais si ce code compile, c'est que tu as défini son constructeur comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    public Trajet(Ville villeDepart, Ville villeArrivee) {
    ...
    }
    Seulement voilà, dans le modèle de ta combo, il y a des String (c'est ce que tu y a mis avec les appels de addItem()). Et le constructeur s'attend à avoir des Ville en argument. Et un String ne peut être casté en Ville : ces 2 classes ne sont pas compatibles (Ville n'étend pas directement ou indirectement String, et n'est pas String).

    Maintenant, pourquoi as-tu pu mettre des String dans le modèle de ta combo, alors que tu as créé ta combo avec un Vector<Ville> ? Surtout que quand on construit un JComboBox avec un Vector, ce Vector est utilisé pour stocker les valeurs dans le modèle. La raison est que les paramètres des classes (les trucs qui sont entre < et >) ne sont valables qu'à la compilation : à l'exécution, ils n'existent plus, et une variable déclarée Vector<Ville> peut contenir des String, ou des Integer, des Ville ou n'importe quoi d'autre, qui étend Object.

    Pourquoi alors le contrôle à la compilation n'a pas pu fonctionner : parce que tu n'as pas indiqué de type de paramétrage pour la JComboBox. C'est comme si tu avais dit : "je ne veux pas de contrôle de type sur la JComboBox". Et la compilateur permet de faire un JComboBox sans contrôle de type qui prend un Vector qui a un contrôle de type. Mais tu dois avoir dans ton IDE des warnings qui t'indiquent que tu n'as pas mis le paramétrage du type.

    En résumé, malgré que tu aies déclaré le Vector, comme paramétré avec des Ville, paramètre n'existant qu'à la compilation, à l'exécution le Vector contient que des String, ce qu'il peut faire (puisque les paramètres n'existent plus à la compilation). Et tu as pu y mettre des String parce que tu n'as pas dit que JComboBox devait être paramétré Ville, donc les appels de addItem() avec des String ont pu compiler.


    Tu aurais dû écrire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Vector<Ville> tableauVille=new Vector<Ville>();
    private JComboBox<Ville> comboBoxVilleDepart=new JComboBox<>(tableauVille);
    A droite, le <> n'indique pas le type, parce que celui du type de déclaration, à gauche, est suffisant pour que le compilateur "comprenne" qu'il s'agit d'un JComboBox<Ville> (depuis Java 7 seulement).

    Et maintenant, il y a un contrôle. Donc ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    comboBoxVilleDepart.addItem(marseille.getNom());
    ...
    ne compile plus. Parce que getNom() est du String et que le paramétrage de JComboBox dit qu'on doit passer à la méthode addItem une instance de Ville

    Il faut donc écrire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    comboBoxVilleDepart.addItem(marseille);
    ...
    Et là, tu n'auras plus d'erreur de compilation, ni d'exécution. Toutefois, tu vas te rendre compte qu'on ne voit plus de nom de villes s'afficher dans les combo, mais des "formules étranges" : par défaut un JComboBox ne sait afficher que des String, donc pour afficher des Ville, il utilise la méthode toString() de Ville et comme tu n'as pas implémenté cette méthode dans la classe Ville, c'est celle de la classe Object qui est appelée, d'où la formule étrange. Implémentes la méthode toString() de Ville pour qu'elle retourne le nom de la ville (Tu peux également utiliser la notion de renderer de la JComboBox, mais si ça permet de faire tout ce qu'on veut en matière d'affichage (y compris mettre des images, des couleurs etc), c'est un peu plus complexe).

    Avec ce système, tu ne seras même plus obligé de faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    int contentsVilleDepart = comboBoxVilleDepart.getSelectedIndex();
    int contentsVilleArrivee = comboBoxVilleArrivee.getSelectedIndex();
    if(contentsVilleDepart !=contentsVilleArrivee) {
    		    		 Trajet trajetUn
    		    		 =new Trajet(
    		    				 tableauVille.get(contentsVilleDepart),
    		    				 tableauVille.get(contentsVilleArrivee));
    D'ailleurs, tu pourras utiliser directement getSelectedItem pour récupérer l'instance de Ville :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Ville villeDepart = comboBoxVilleArrivee.getSelectedItem();
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  3. #3
    Invité
    Invité(e)
    Par défaut Merci
    merci j'avais pas vu !!!!! pffu erreur de debutant je vais essayer ca merci

  4. #4
    Invité
    Invité(e)
    Par défaut Mon code
    voici mon code apres correction :

    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
     
    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);
    		    }  
    		  }  
     
     
    }
    faudrait que je rajoute un petit message pour demander à l'utilisateur de choisir 2 villes et ptete un ptit try_trow catch pour le cas ou il aurait oublié mais sinon ca marche nickel merciiii

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

Discussions similaires

  1. Petit soucis avec les doubles
    Par yakamoneye dans le forum Débuter
    Réponses: 30
    Dernier message: 08/06/2008, 11h04
  2. Un petit souci avec les dates
    Par Ben-o dans le forum SQL Procédural
    Réponses: 11
    Dernier message: 27/09/2007, 18h42
  3. Réponses: 10
    Dernier message: 26/10/2006, 12h25
  4. petit soucis avec les listes
    Par Death83 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 03/09/2005, 10h08

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