Ajouter un commentaire

ramzi ramzi
compilateur

salut
voici ce que je fait avant de lire ton reponce


/*
 * Editor.java
 *
 * Created on 17. Mنrz 2008, 17:13
 */
package Interface;

/**
 *
 * @author  RAMZI
 */
public class Editor extends javax.swing.JFrame
{

    /** Creates new form Editor */
    @SuppressWarnings("deprecation")
    public Editor()
    {
        initComponents();
        Compile.setEnabled(false);
    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        Consol = new javax.swing.JTextArea();
        jScrollPane1 = new javax.swing.JScrollPane();
        Editor = new javax.swing.JEditorPane();
        Compile = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Editor"));

        Consol.setColumns(20);
        Consol.setEditable(false);
        Consol.setRows(5);
        jScrollPane2.setViewportView(Consol);

        Editor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                Enable_keyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(Editor);

        Compile.setText("Compile");
        Compile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CompileActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(Compile)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 717, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Compile)))
        );

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

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void CompileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CompileActionPerformed

        String Resultat_compile = "";
        String ch1 = null;
        String ch2 = null;
        String[] tab_ref_chaine = {"yxcv b", "asdf", "qwertz", "ramzi"};
        int cont_error = 1;

//verification si l'editor est vide ou nom
        if (Editor.getText().isEmpty())
        {
            Resultat_compile = "Nothing to compile";
        } else
        {
//recuperation de tout le text ecrit dans une chaine de caractere            
            String chaine = Editor.getText();
//le spliter dans un tableau de string
            String[] tab_chaine = chaine.split("\n");
//debarrassement des espaces doublee  //a refaire      
            for (int i = 0; i < tab_chaine.length; i++)
            {
                chaine = "";
                chaine = tab_chaine[i];
                tab_chaine[i] = "";
                for (int j = 0; j < chaine.length(); j++)
                {
                    int cont = chaine.indexOf(" ");
                    ch1 = chaine.substring(cont + 1);
                    if (ch1.indexOf(" ") == 0)
                    {
                        ch1 = ch1.substring(1);
                    }
                    ch2 = chaine.substring(0, cont + 1);
                }
                chaine = ch2 + ch1;
// re remplissage du tableau avec les chaine sans occurences des espaces
                tab_chaine[i] = chaine;
            }
//            for (int i = 0; i < tab_chaine.length; i++)
//            {
//                Resultat_compile = Resultat_compile.concat(tab_chaine[i] + "\n");
//            }
//compilation par rapport a un reference
//            System.out.println("\ntab_chaine[tab_chaine.length-1] :"+tab_chaine[tab_chaine.length-1]);
//            System.out.println("tab_chaine[tab_chaine.length-1].length() :"+tab_chaine[tab_chaine.length-1].length());
//            System.out.println("dernier char de dernier element du tableau :"+tab_chaine[tab_chaine.length-1].substring(tab_chaine[tab_chaine.length-1].length()-1));
            for (int i = 0; i < tab_chaine.length; i++)
            {
//                System.out.println("tab_chaine[" + i + "] :" + tab_chaine[i]);
                if (tab_chaine[i].equals(tab_chaine[tab_chaine.length - 1]))
                {
                    tab_chaine[i] = tab_chaine[i].concat(" ");
                }
                for (int j = 0; j < tab_ref_chaine.length; j++)
                {
//                 System.out.println("extraction d'element "+i+" a comparer avec la ref "+j+" de ref :"+tab_chaine[i]);
                    if (!tab_chaine[i].substring(0, tab_chaine[i].length() - 1).equals(tab_ref_chaine[j]))
                    {
//                     System.out.println("l'element "+tab_chaine[i]+" est different de "+tab_ref_chaine[j]);
                        if (j == tab_ref_chaine.length - 1)
                        {
                            Resultat_compile += "Error in Line(s): "+cont_error+" . ";
                            cont_error += 1;
                        }
                    } else
                    {
//                     System.out.println("l'element "+tab_chaine[i]+" est le meme que "+tab_ref_chaine[j]);
                        Resultat_compile = "Compile Seccessful";
                    }
                }
            }
//System.out.println("nb d'erreur : "+cont_error);
        }
        Consol.append("Compiling...\n");
        Consol.append(Resultat_compile + "\n");
    }//GEN-LAST:event_CompileActionPerformed

    private void Enable_keyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_Enable_keyReleased
        Consol.setText("");
        if (Editor.getText() != "")
        {
            Compile.setEnabled(true);
        }
    }//GEN-LAST:event_Enable_keyReleased

    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {

            public void run()
            {
                new Editor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Compile;
    private javax.swing.JTextArea Consol;
    private javax.swing.JEditorPane Editor;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}

note : tu peut compiler ce code pour voir le resultat
"je developpe avec netbeans 6 "

il reste quelques truc tel que :
-le code ne verifie que le dernier element de tab_ref_chaine dans la partie de verification des mots( possible qu'il faut changer le boucle for par while)
- j'arrive pas a concatuner les "cont_error" dans la chaine "Resultat_compile"

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
 M   M  DDD    QQQ    Y   Y   CCC 
MM MM D D Q Q Y Y C
M M M D D Q Q Y C
M M D D Q QQ Y C
M M DDD QQQQ Y CCC
Q