Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.20 KB | None | 0 0
  1. //RESEARCH jframe code
  2.  
  3.  
  4.  
  5.  
  6. /*
  7. * To change this license header, choose License Headers in Project Properties.
  8. * To change this template file, choose Tools | Templates
  9. * and open the template in the editor.
  10. */
  11. package InterfaceDico;
  12.  
  13. import GestionDictionnaire.GestionDico;
  14. import javax.swing.JOptionPane;
  15.  
  16. /**
  17. *
  18. * @author Franck
  19. */
  20. public class RechercherMot extends javax.swing.JFrame {
  21.  
  22. /**
  23. * Creates new form RechercherMot
  24. */
  25. public RechercherMot() {
  26. initComponents();
  27. }
  28.  
  29. /**
  30. * This method is called from within the constructor to initialize the form.
  31. * WARNING: Do NOT modify this code. The content of this method is always
  32. * regenerated by the Form Editor.
  33. */
  34. @SuppressWarnings("unchecked")
  35. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  36. private void initComponents() {
  37.  
  38. jPanel1 = new javax.swing.JPanel();
  39. jLabel1 = new javax.swing.JLabel();
  40. jLabel2 = new javax.swing.JLabel();
  41. valider = new javax.swing.JButton();
  42. entrer_mot = new javax.swing.JTextField();
  43. jScrollPane1 = new javax.swing.JScrollPane();
  44. entrer_definition = new javax.swing.JTextArea();
  45.  
  46. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  47.  
  48. jLabel1.setText(" RECHERCHER MOT ");
  49.  
  50. jLabel2.setText("MOT A RECHERCHER :");
  51.  
  52. valider.setText("RECHERCHER");
  53. valider.addActionListener(new java.awt.event.ActionListener() {
  54. public void actionPerformed(java.awt.event.ActionEvent evt) {
  55. validerActionPerformed(evt);
  56. }
  57. });
  58.  
  59. entrer_mot.addActionListener(new java.awt.event.ActionListener() {
  60. public void actionPerformed(java.awt.event.ActionEvent evt) {
  61. entrer_motActionPerformed(evt);
  62. }
  63. });
  64.  
  65. entrer_definition.setColumns(20);
  66. entrer_definition.setRows(5);
  67. jScrollPane1.setViewportView(entrer_definition);
  68.  
  69. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  70. jPanel1.setLayout(jPanel1Layout);
  71. jPanel1Layout.setHorizontalGroup(
  72. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  73. .addGroup(jPanel1Layout.createSequentialGroup()
  74. .addContainerGap()
  75. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  76. .addComponent(jScrollPane1)
  77. .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  78. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  79. .addGap(0, 0, Short.MAX_VALUE)
  80. .addComponent(valider))
  81. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  82. .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
  83. .addGap(18, 18, 18)
  84. .addComponent(entrer_mot, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE)))
  85. .addContainerGap())
  86. );
  87. jPanel1Layout.setVerticalGroup(
  88. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89. .addGroup(jPanel1Layout.createSequentialGroup()
  90. .addContainerGap()
  91. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
  92. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  93. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  94. .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
  95. .addComponent(entrer_mot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  96. .addGap(18, 18, 18)
  97. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
  98. .addGap(18, 18, 18)
  99. .addComponent(valider)
  100. .addContainerGap())
  101. );
  102.  
  103. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  104. getContentPane().setLayout(layout);
  105. layout.setHorizontalGroup(
  106. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  107. .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  108. );
  109. layout.setVerticalGroup(
  110. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  111. .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  112. );
  113.  
  114. pack();
  115. }// </editor-fold>
  116.  
  117. private void validerActionPerformed(java.awt.event.ActionEvent evt) {
  118. // TODO add your handling code here:
  119. String mot= entrer_mot.getText();
  120. entrer_mot.setText("");
  121. String definition = entrer_definition.getText();
  122. entrer_definition.setText("");
  123.  
  124.  
  125. if(mot.equalsIgnoreCase("")){
  126. JOptionPane.showMessageDialog(null, "données incorrectes", "Erreur", JOptionPane.ERROR_MESSAGE);
  127. }
  128. else{
  129. GestionDico dico =new GestionDico();
  130. dico.RechercherMot(mot);
  131.  
  132. }
  133. }
  134.  
  135. private void entrer_motActionPerformed(java.awt.event.ActionEvent evt) {
  136. // TODO add your handling code here:
  137.  
  138. }
  139.  
  140. /**
  141. * @param args the command line arguments
  142. */
  143. public static void main(String args[]) {
  144. /* Set the Nimbus look and feel */
  145. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  146. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  147. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  148. */
  149. try {
  150. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  151. if ("Nimbus".equals(info.getName())) {
  152. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  153. break;
  154. }
  155. }
  156. } catch (ClassNotFoundException ex) {
  157. java.util.logging.Logger.getLogger(RechercherMot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  158. } catch (InstantiationException ex) {
  159. java.util.logging.Logger.getLogger(RechercherMot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  160. } catch (IllegalAccessException ex) {
  161. java.util.logging.Logger.getLogger(RechercherMot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  162. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  163. java.util.logging.Logger.getLogger(RechercherMot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  164. }
  165. //</editor-fold>
  166.  
  167. /* Create and display the form */
  168. java.awt.EventQueue.invokeLater(new Runnable() {
  169. public void run() {
  170. new RechercherMot().setVisible(true);
  171. }
  172. });
  173. }
  174.  
  175. // Variables declaration - do not modify
  176. private javax.swing.JTextArea entrer_definition;
  177. private javax.swing.JTextField entrer_mot;
  178. private javax.swing.JLabel jLabel1;
  179. private javax.swing.JLabel jLabel2;
  180. private javax.swing.JPanel jPanel1;
  181. private javax.swing.JScrollPane jScrollPane1;
  182. private javax.swing.JButton valider;
  183. // End of variables declaration
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190. //management function code
  191.  
  192.  
  193.  
  194.  
  195. public void RechercherMot(String mot){
  196. String ret="select * from dictionnaire where mot=?";
  197. try {
  198. PreparedStatement ps = (PreparedStatement) ConnectionDico.getCon().prepareStatement(ret);
  199.  
  200. ps.setString(1,mot);
  201. //execution
  202. ResultSet resultat= ps.executeQuery();
  203. while(resultat.next()){
  204. System.out.println("mot = " +resultat.getString("mot")+" "+"definition = "+resultat.getString("definition")+" ");
  205. JOptionPane.showMessageDialog(null,"votre mot a été trouvé avec succès et sa définition est la suivante:n"+" mot = " +resultat.getString("mot")+" "+"/ definition = "+resultat.getString("definition")+" ","reussite",JOptionPane.INFORMATION_MESSAGE);
  206. }
  207. } catch (SQLException ex) {
  208. Logger.getLogger(GestionDico.class.getName()).log(Level.SEVERE, null, ex);
  209. JOptionPane.showMessageDialog(null, "le mot n'a pas été retrouvé dans le dictionnaire", "Erreur", JOptionPane.ERROR_MESSAGE);
  210. }
  211.  
  212. }
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement