import java.awt.*;
import java.text.*;
import javax.swing.JButton;
public class moteurCommande implements ActionListener {
	
	
	Commande parent; //une référence a la Commande
	
	NumberFormat formatNombres = NumberFormat.getInstance();
	
	
	
	moteurCommande(Commande parent) {
		this.parent = parent;
	}
	
	public void actionPerformed(ActionEvent evt) {
			
		 //L'utilisateur a clquer sur le bouton commander 
			
			String quantiterChoisie = parent.champTexteQuantiter.getText();
			String modelChoisi = parent.champTexteModel.getText();
			String Confirmation = parent.champTexteConfirmationCommande.getText();
			int quantiter = Integer.parseInt(quantiterChoisie);
			
			JButton boutonCliqué = (JButton) evt.getSource();
			
			
			if (!"".equals(quantiterChoisie)) {
				quantiter =
					 (int) formatNombres.parse(
						quantiterChoisie,
						new ParsePosition(0)).
						doubleValue();
			}
			
			Object sourceEvénement = evt.getSource();
			
	
			
			if (sourceEvénement == parent.boutonSoumettre){
				
				if( quantiter <= 3 && modelChoisi == "renault"){
				javax.swing.JOptionPane.showConfirmDialog(null,
						"merci d'avoir commander " +quantiter+ " de voiture(s) de marque " +modelChoisi+ " .",
						"Bon de comande.",
						javax.swing.JOptionPane.PLAIN_MESSAGE);
						return;
				}else if (quantiter >= 4) {
					javax.swing.JOptionPane.showConfirmDialog(null,
							"Désoler mais je ne pourrias pas livrer autant de voiture en une seule fois .",
							"Bon de comande.",
							javax.swing.JOptionPane.PLAIN_MESSAGE);
							return;
				}
			}
	}		
}
			
		
 
	
Partager