Partage
  • Partager sur Facebook
  • Partager sur Twitter

Un bouton sans effet parmis 4 boutons

GUI + Evenements

Sujet résolu
Anonyme
    26 mars 2010 à 22:17:43

    Bonsoir,

    J'ai un problème étrange avec un bouton que je n'arrive pas à faire fonctionner >_<:'(
    J'ai pourtant copier-coller le code de mes 3 autres boutons et ceux-ci fonctionne parfaitement bien.
    J'ai bien sur changer le nom de la variable JButton pour le nouveau bouton et je l'ai bien déclaré et ajouté au panneau comme les autres.

    Il s'agit du bouton "toto" qui doit aller dans le panneau 2 normalement mais que j'ai déplacé pour voir si ça changeait quelque chose.
    Il ne s'appelait pas toto mais j'ai même changé le nom pour voir si le problème ne venait pas de là xD

    S'il vous plait, aidez-moi, vous êtes mon dernier espoir o_O

    package GUI;
    
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.GridLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.Connection;
    import java.sql.SQLException;
    
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JToolBar;
    
    import RessourceDB.InitDB;
    import RessourceDB.ZoneDeTest;
    
    public class FormulaireSuppressionAll extends JFrame implements ActionListener{
    
    	private JLabel labClient, labCommande, labProduit, labMessage;
    	private JComboBox listeCli = new JComboBox();
    	private JComboBox listeCom = new JComboBox();
    	private JComboBox listeProd = new JComboBox();
    	private JButton home, precedent, delClient, delCommande, delGlace, toto;
    	private JPanel panneau1, panneau2, panneau3, panneau4;
    	private Container conteneur;
    	private JToolBar barre;
    	InitDB maInitDB = null;
    	Connection conn = null;
    	private String reqSuppression;
    	private int choixCommit = 1;
    	private boolean flag = false;
    	private int nbrID;
    	private String lineSequential;
    	private int nbrIDCli, nbrIDCom, nbrIDProd;
    	private int[] tabIDCli = new int[199];
    	private int[] tabIDCom = new int[199];
    	private int[] tabIDProd = new int[199];
    	private int choixCritique=1;
    	private int id = 0;
    	
    	FormulaireSuppressionAll()
    	{
    		super("Suppression diverses");
    
    		conteneur = new Container();
    		conteneur = getContentPane();
    		conteneur.setLayout(new GridLayout(6,1));
    
    		panneau1 = new JPanel();
    		panneau2 = new JPanel();
    		panneau3 = new JPanel();
    		panneau4 = new JPanel();
    
    		barre = new JToolBar();
    		
    		home = new JButton(new ImageIcon("menu1.jpg"));
    		home.setToolTipText("Ecran d'acceuil");
    		home.addActionListener(this);
    
    		precedent = new JButton(new ImageIcon("prec.jpg"));
    		precedent.setToolTipText("Fenêtre précédente");
    		precedent.addActionListener(this);
    		
    		barre.add(home);
    		barre.add(precedent);
    		
    		labClient = new JLabel("Client à supprimer : ");
    		labCommande = new JLabel("Commande à supprimer : ");
    		labProduit = new JLabel("Produit à supprimer : ");
    
    
    		try {
    			maInitDB = new InitDB();
    			maInitDB.connecter();
    			conn = maInitDB.getConn();
    		    
    			nbrIDCli = ZoneDeTest.getNbrIDclient(conn);
    			
    			for (int i = 0;i < nbrIDCli; i++)
    			{
    			tabIDCli[i] = ZoneDeTest.getLineSequentialIDclient(conn,i);
    			lineSequential = ZoneDeTest.getLineSequentialClient(conn,i);
    			listeCli.addItem(lineSequential);
    			}	
    			
    
    			nbrIDCom = ZoneDeTest.getNbrIDcommande(conn);
    			
    			for (int i = 0;i < nbrIDCom; i++)
    			{
    			tabIDCom[i] = ZoneDeTest.getLineSequentialIDcommande(conn,i);
    			lineSequential = ZoneDeTest.getLineSequentialCommande(conn,i);
    			listeCom.addItem(lineSequential);
    			}	
    			
    			nbrIDProd = ZoneDeTest.getNbrIDprod(conn);
    			
    			for (int i = 0;i < nbrIDProd; i++)
    			{
    			tabIDProd[i] = ZoneDeTest.getLineSequentialIDprod(conn,i);
    			lineSequential = ZoneDeTest.getLineSequentialProd(conn,i);
    			listeProd.addItem(lineSequential);
    			}	
    		} catch (ClassNotFoundException e) {
    			JOptionPane.showMessageDialog(null,"========> Problème de driver");
    		} catch (SQLException e) {
    			JOptionPane.showMessageDialog(null,"========> Problème SQL");
    		} finally {
    						try {
    							 maInitDB.fermer();
    							} 
    						catch (SQLException e) {}
    				  }
    
    		labMessage = new JLabel("Nombre de client : "+nbrIDCli+"|\nNombre de commandes :"+nbrIDCom+"|\nNombre de  glaces : "+nbrIDProd);
    		
    		delClient = new JButton(new ImageIcon("delete.jpg"));
    		delClient.setMargin(new Insets(0,0,0,0));
    		delClient.setBorderPainted(false);
    		delClient.addActionListener(this);
    		
    		delCommande = new JButton(new ImageIcon("delete.jpg"));
    		delCommande.setMargin(new Insets(0,0,0,0));
    		delCommande.setBorderPainted(false);
    		delCommande.addActionListener(this);
    		
    		toto = new JButton(new ImageIcon("delete.jpg"));
    		toto.setMargin(new Insets(0,0,0,0));
    		toto.setBorderPainted(false);
    		toto.addActionListener(this);
    
    		delGlace = new JButton(new ImageIcon("delete.jpg"));
    		delGlace.setMargin(new Insets(0,0,0,0));
    		delGlace.setBorderPainted(false);
    		delGlace.addActionListener(this);
    		
    		getContentPane().add(barre,BorderLayout.NORTH);
    		
    		panneau1.add(labClient);
    		panneau1.add(listeCli);
    		panneau1.add(delClient);
    		
    		panneau2.add(labCommande);
    		panneau2.add(listeCom);
    		panneau2.add(delCommande);
    		
    		panneau3.add(labProduit);
    		panneau3.add(listeProd);
    		panneau3.add(delGlace);
    		
    		panneau4.add(labMessage);
    		panneau4.add(toto);
    		
    		conteneur.add(panneau1);
    		conteneur.add(panneau2);
    		conteneur.add(panneau3);
    		conteneur.add(panneau4);
    		
    	
    		setSize(600,350);
    		setLocationRelativeTo(null);
    		setVisible(true);
    		setResizable(false);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    	}
    	
    	public void actionPerformed(ActionEvent event){
    		if(event.getSource()==delClient)
    		{
    			int identificationDEL = 1;
    			identificationDEL = listeCli.getSelectedIndex();
    			identificationDEL = tabIDCli[identificationDEL];
    			
    			
    			choixCritique = JOptionPane.showConfirmDialog(null,"Etes vous sur de vouloir supprimer ce record : "+listeCli.getSelectedItem()+" ?","Information importante",JOptionPane.WARNING_MESSAGE);
                            
                if (choixCritique == 0)
                {
        		try {
        			maInitDB = new InitDB();
        			maInitDB.connecter();
        		    conn = maInitDB.getConn();
        		    id = identificationDEL;
        			flag = ZoneDeTest.deleteCli(conn,id);
        			
        			if (flag)
        			{
        			JOptionPane.showMessageDialog(null,"Suppresion du client effectuée !","Successful",JOptionPane.INFORMATION_MESSAGE);
        			nbrIDCli = ZoneDeTest.getNbrIDclient(conn);
        			
        			for (int i = 0;i < nbrID; i++)
        			{
        			tabIDCli[i] = ZoneDeTest.getLineSequentialIDclient(conn,i);
        			lineSequential = ZoneDeTest.getLineSequentialClient(conn,i);
        			listeCli.addItem(lineSequential);
        			}
        			setVisible(false);
        			FormulaireSuppressionAll majGUI= new FormulaireSuppressionAll();
        			
        			}	
        			else
        				JOptionPane.showMessageDialog(null,"La suppression du client a échouée !","FATAL ERROR",JOptionPane.ERROR_MESSAGE);
        			
        			
        		} catch (ClassNotFoundException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème de driver");
        		} catch (SQLException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème SQL");
        		} finally {
        			try {
        				maInitDB.fermer();
        				} catch (SQLException e) {
        				  }
        		}
        	}
    	
    		}
    		
    		if(event.getSource()==delCommande)
    		{
    			int identificationDEL = 1;
    			identificationDEL = listeCom.getSelectedIndex();
    			identificationDEL = tabIDCom[identificationDEL];
    			
    			choixCritique = JOptionPane.showConfirmDialog(null,"Etes vous sur de vouloir supprimer ce record : "+listeCom.getSelectedItem()+" ?","Information importante",JOptionPane.WARNING_MESSAGE);
                
                if (choixCritique == 0)
                {
        		try {
        			maInitDB = new InitDB();
        			maInitDB.connecter();
        		    conn = maInitDB.getConn();
    
        		    id = identificationDEL;
        			flag = ZoneDeTest.deleteCom(conn,id);
        			
        			if (flag)
        			{
        			JOptionPane.showMessageDialog(null,"Suppresion de la commande effectuée !","Successful",JOptionPane.INFORMATION_MESSAGE);
        			nbrIDCom = ZoneDeTest.getNbrIDcommande(conn);
        			
        			for (int i = 0;i < nbrID; i++)
        			{
        			tabIDCli[i] = ZoneDeTest.getLineSequentialIDcommande(conn,i);
        			lineSequential = ZoneDeTest.getLineSequentialCommande(conn,i);
        			listeCli.addItem(lineSequential);
        			}
        			setVisible(false);
        			FormulaireSuppressionAll majGUI= new FormulaireSuppressionAll();
       
        			}
        			else
        				JOptionPane.showMessageDialog(null,"La suppression de la commande à échouée !","FATAL ERROR",JOptionPane.ERROR_MESSAGE);
        			
        			
        		} catch (ClassNotFoundException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème de driver");
        		} catch (SQLException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème SQL");
        		} finally {
        			try {
        				maInitDB.fermer();
        				} catch (SQLException e) {
        				  }
        		}
        	}
    		}
    	
    		
    		if(event.getSource()=="toto")
    		{
    			JOptionPane.showMessageDialog(null,"Bouton X appuyé","Information importante",JOptionPane.WARNING_MESSAGE);
    			
    			/*
    			try {
        			maInitDB = new InitDB();
        			maInitDB.connecter();
        		    conn = maInitDB.getConn();
    			
        		    choixCritique = JOptionPane.showConfirmDialog(null,"Etes vous sur de vouloir supprimer toutes les commandes ? : "+listeCli.getSelectedItem()+" ?","!!!!! ATTENTION !!!!!",JOptionPane.WARNING_MESSAGE);
        		    if (choixCritique == 0) flag = ZoneDeTest.deleteAllCom(conn);
        		    else if(choixCritique == 1)  JOptionPane.showConfirmDialog(null,"Action annulée avec succès !"+listeCli.getSelectedItem()+" ?","Ouf !",JOptionPane.INFORMATION_MESSAGE);
    			if (flag)
    			{
    			JOptionPane.showMessageDialog(null,"Suppression totale des commandes réussie !","Successful",JOptionPane.INFORMATION_MESSAGE);
    			//setVisible(false);
    			//FormulaireSuppressionAll majGUI= new FormulaireSuppressionAll();
    			}
    			else
    				JOptionPane.showMessageDialog(null,"La suppression de toutes les commandes à échouée !","FATAL ERROR",JOptionPane.ERROR_MESSAGE);
    			
    			
    			} catch (ClassNotFoundException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème de driver");
        		} catch (SQLException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème SQL");
        		} finally {
        			try {
        				maInitDB.fermer();
        				} catch (SQLException e) { }
        				  }
        		
        	*/	
    		}
    		
    		if(event.getSource()==delGlace)
    		{
    			int identificationDEL = 1;
    			identificationDEL = listeProd.getSelectedIndex();
    			identificationDEL = tabIDProd[identificationDEL];
    			
    			choixCritique = JOptionPane.showConfirmDialog(null,"Etes vous sur de vouloir supprimer ce record : "+listeProd.getSelectedItem()+" ?","Information importante",JOptionPane.WARNING_MESSAGE);
                
                if (choixCritique == 0)
                {
        		try {
        			maInitDB = new InitDB();
        			maInitDB.connecter();
        		    conn = maInitDB.getConn();
        		    
        		    id = identificationDEL;
        			flag = ZoneDeTest.deleteProd(conn,id);
        			
        			if (flag)
        			{	
        			JOptionPane.showMessageDialog(null,"Suppresion de la glace effectuée !","Successful",JOptionPane.INFORMATION_MESSAGE);
        			nbrIDProd = ZoneDeTest.getNbrIDclient(conn);
        			
        			for (int i = 0;i < nbrID; i++)
        			{
        			tabIDProd[i] = ZoneDeTest.getLineSequentialIDprod(conn,i);
        			lineSequential = ZoneDeTest.getLineSequentialProd(conn,i);
        			listeProd.addItem(lineSequential);
        			}	
        			setVisible(false);
        			FormulaireSuppressionAll majGUI= new FormulaireSuppressionAll();
        			}
        			else
        				JOptionPane.showMessageDialog(null,"La suppression de la glace a échouée !","FATAL ERROR",JOptionPane.ERROR_MESSAGE);
        			
        			
        		} catch (ClassNotFoundException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème de driver");
        		} catch (SQLException e) {
        			JOptionPane.showMessageDialog(null,"========> Problème SQL");
        		} finally {
        			try {
        				maInitDB.fermer();
        				} catch (SQLException e) {
        				  }
        		}
        	}
    	
    		}
    		
    		
    		
    		
    		if(event.getSource()==home || event.getSource()==precedent)
    		{
    			setVisible(false);
    			ObjetGraphique application = new ObjetGraphique();
    		}
    		
    	}
    }
    


    J'ai mit tout le code de la fonction associé en commentaire et une boîte de dialogue à la place pour voir si le clique sur le bouton fonctionne mais en vain.
    Donc ce n'est même pas un problème d'accolade et/ou de code dans le if du listener...
    • Partager sur Facebook
    • Partager sur Twitter
      26 mars 2010 à 22:27:36

      ligne 278:
      if(event.getSource()==toto)
      //et non pas
      if(event.getSource()=="toto")
      
      </span>
      • Partager sur Facebook
      • Partager sur Twitter
      Anonyme
        26 mars 2010 à 22:32:22

        Merci infiniment ! Quelle rapidité !
        Ce sont toujours les erreurs qui tienne sur 2, 3 caractères qui sont les pires :lol:

        Le problème de ce sujet est résolu
        • Partager sur Facebook
        • Partager sur Twitter

        Un bouton sans effet parmis 4 boutons

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown