import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.UIManager; public class FenetreDesClients extends JFrame implements ActionListener { private JLabel bidon1 = new JLabel(" "); private JLabel labPre = new JLabel("Prénom "); private JTextField texPre = new JTextField(); private JLabel bidon2 = new JLabel(" "); private JLabel labNom = new JLabel("Nom "); private JTextField texNom = new JTextField(); private JLabel bidon3 = new JLabel(" "); private JLabel labAdr = new JLabel("Adresse "); private JTextField texAdr = new JTextField(); private JLabel bidon4 = new JLabel(" "); private JButton ajoute = new JButton("Ajouter ce client"); private JButton select = new JButton("Faire un query vers la console"); private JLabel bidon5 = new JLabel(" "); String nomBDD; HSQLDBConnector db = HSQLDBConnector.getInstance(); // ************************************************************************* public FenetreDesClients() { super("Fenêtre de clients"); select.addActionListener(this); ajoute.addActionListener(this); Container cont = getContentPane(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; JPanel panneau = new JPanel(); panneau.setLayout(gbl); int p_x[] = { 0, 1, 2, 3, 1, 2, 1, 1, 2, 4, 2, 4, 5 }; int p_y[] = { 0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8 }; int p_larg[] = { 1, 1, 3, 1, 1, 3, 1, 1, 3, 1, 1, 1, 1 }; int p_haut[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; int p_px[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int p_py[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (int i = 0; i < p_x.length; i++) { c.gridx = p_x[i]; c.gridy = p_y[i]; c.gridwidth = p_larg[i]; c.gridheight = p_haut[i]; c.weightx = p_px[i]; c.weighty = p_py[i]; switch (i) { case 0: panneau.add(bidon1, c); break; case 1: panneau.add(labPre, c); break; case 2: panneau.add(texPre, c); break; case 3: panneau.add(bidon2, c); break; case 4: panneau.add(labNom, c); break; case 5: panneau.add(texNom, c); break; case 6: panneau.add(bidon3, c); break; case 7: panneau.add(labAdr, c); break; case 8: panneau.add(texAdr, c); break; case 9: panneau.add(bidon4, c); break; case 10: panneau.add(ajoute, c); break; case 11: panneau.add(select, c); break; case 12: panneau.add(bidon5, c); break; } } cont.add(panneau, BorderLayout.CENTER); setSize(500, 190); pack(); setLocationRelativeTo(this.getParent()); setVisible(true); nomBDD = JOptionPane .showInputDialog(this, "Entrez le nom de la B.D.D."); if ((nomBDD == null) || (nomBDD.equals(""))) nomBDD = new String("bdd_test"); System.out.println("On va traiter la bdd : " + nomBDD); db.setBDD(nomBDD); // on check si la table principale existe déjà : if (db.existe("TABLE_CLIENT") == false) { // on crée alors la table "TABLE_CLIENT" db.creerTableClients(); } addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } }); } // ************************************************************************* public void actionPerformed(ActionEvent e) { if ((JButton) (e.getSource()) == ajoute) { if (testDesChampsVides()) { db.insererUnClientDansBDD(texPre.getText(), texNom.getText(), texAdr.getText()); viderlesChampsTextes(); } } if ((JButton) (e.getSource()) == select) { db.afficherTousLesClientsVersConsole(); } } // ************************************************************************* public boolean testDesChampsVides() { if ((texPre.getText()).equals("") || (texNom.getText()).equals("") || (texAdr.getText()).equals("")) { JOptionPane.showMessageDialog(this, "Aucun champ ne peut rester vide !", "Attention", JOptionPane.ERROR_MESSAGE); return false; } return true; } // ************************************************************************* public void viderlesChampsTextes() { texPre.setText(""); texNom.setText(""); texAdr.setText(""); } // ************************************************************************* public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { System.out.println(e); } new FenetreDesClients(); } // ************************************************************************* }