2016-12-03 2 views
0
//RESEARCH jframe code 




/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package InterfaceDico; 

import GestionDictionnaire.GestionDico; 
import javax.swing.JOptionPane; 

/** 
* 
* @author Franck 
*/ 
public class RechercherMot extends javax.swing.JFrame { 

    /** 
    * Creates new form RechercherMot 
    */ 
    public RechercherMot() { 
     initComponents(); 
    } 

    /** 
    * This method is called from within the constructor to initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is always 
    * regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code">       
    private void initComponents() { 

     jPanel1 = new javax.swing.JPanel(); 
     jLabel1 = new javax.swing.JLabel(); 
     jLabel2 = new javax.swing.JLabel(); 
     valider = new javax.swing.JButton(); 
     entrer_mot = new javax.swing.JTextField(); 
     jScrollPane1 = new javax.swing.JScrollPane(); 
     entrer_definition = new javax.swing.JTextArea(); 

     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 

     jLabel1.setText("              RECHERCHER MOT "); 

     jLabel2.setText("MOT A RECHERCHER :"); 

     valider.setText("RECHERCHER"); 
     valider.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       validerActionPerformed(evt); 
      } 
     }); 

     entrer_mot.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       entrer_motActionPerformed(evt); 
      } 
     }); 

     entrer_definition.setColumns(20); 
     entrer_definition.setRows(5); 
     jScrollPane1.setViewportView(entrer_definition); 

     javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 
     jPanel1.setLayout(jPanel1Layout); 
     jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel1Layout.createSequentialGroup() 
       .addContainerGap() 
       .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
        .addComponent(jScrollPane1) 
        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 
         .addGap(0, 0, Short.MAX_VALUE) 
         .addComponent(valider)) 
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 
         .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE) 
         .addGap(18, 18, 18) 
         .addComponent(entrer_mot, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE))) 
       .addContainerGap()) 
     ); 
     jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel1Layout.createSequentialGroup() 
       .addContainerGap() 
       .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addComponent(entrer_mot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
       .addGap(18, 18, 18) 
       .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE) 
       .addGap(18, 18, 18) 
       .addComponent(valider) 
       .addContainerGap()) 
     ); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
     ); 

     pack(); 
    }// </editor-fold>       

    private void validerActionPerformed(java.awt.event.ActionEvent evt) {           
     // TODO add your handling code here: 
     String mot= entrer_mot.getText(); 
     entrer_mot.setText(""); 
     String definition = entrer_definition.getText(); 
     entrer_definition.setText(""); 


      if(mot.equalsIgnoreCase("")){ 
       JOptionPane.showMessageDialog(null, "données incorrectes", "Erreur", JOptionPane.ERROR_MESSAGE); 
      } 
     else{ 
       GestionDico dico =new GestionDico(); 
       dico.RechercherMot(mot); 

ここで私がenter_definition=setText(dico.RechercherMot(mot))を実行すると、エラーが発生しました。検索結果をjtextareaに表示したい

+1

エラーは何ですか?例外スタックトレースまたはエラーの詳細を送信します。 – Blip

+0

エラー:voidは文字列に変換できません。私は私の機能の結果を印刷したいのですがどうすればいいですか? –

+0

jtextareaにそれを表示します –

答えて

0

RechercherMot(String mot)の返品タイプは無効です。それは何も返されていないということです。今度はenter_definition.setText(dico.RechercherMot(mot))を使用しました。ここでenter_definitionJTextAreaのインスタンスであり、関数setTextはパラメータとしてStringを必要とします。しかし、あなたのdico.RechercherMot(mot)は無効か何も返しません。だから、のvoidを文字列に変換できないというコンパイルエラーが発生します。あなたはStringRechercherMot(String mot)の戻り値の型を変更し、方法でreturnステートメントを使用して、有効なStringを返す必要がエラーを除去するために、今すぐ

ここでは、実行中のクエリのテキスト形式の結果セットを返さなければならないと述べています。そして、ループ内while(resultat.next())

System.out.println("mot = " +resultat.getString("mot")+" "+"definition = "+resultat.getString("definition")+" "); 

を交換

String result = ""; 

:だから、私の提案は、あなたがString変数がresultを言うと、あなたのようなプリペアドステートメントを作成する前に、空の文字列に初期化宣言するかもしれないということです

result += "mot = " +resultat.getString("mot")+" "+"definition = "+resultat.getString("definition")+" \n"; 

最後に、方法の最後の行で、catchブロックの後に挿入:もちろん

return result; 

Stringvoidからメソッドの戻り値の型を変更します。

+0

thankssssssssssssssssss –

関連する問題