Analyseur lexical

Signaler
-
Messages postés
15781
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
8 avril 2021
-
hi, i tried to create an interface were the user inserts thepath of the file to analyze in jTextField1 & when jButton1 clicked the process starts ...but i find a problem of Nullpointer at line 175 !
package compilateur;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.*;
import java.io.FileInputStream;

public class compilateur extends javax.swing.JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1=new JTextField();
JButton jButton1 = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JTextArea jTextArea2 = new JTextArea();

public compilateur(){
try{
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbinit();
}catch(Exception e){
e.printStackTrace();

}
}
public void jbinit()throws Exception{
contentPane=(JPanel)getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(470,500));
setTitle("Analyseur Lexical");
jLabel1.setFont(new java.awt.Font("Garamond",Font.BOLD,20));
jLabel1.setText("Analyseur Lexical");
jLabel1.setBounds(new Rectangle(125, 5, 160, 40));
jLabel2.setText("Chemin");
jLabel2.setBounds(new Rectangle(12, 45, 48, 24));
jTextField1.setBounds(new Rectangle(55,55,178,22));
jButton1.setBounds(new Rectangle(288,48,94,20));
jButton1.setText("Compiler");
jButton1.addActionListener(new compilateur_jButton1_actionAdapter(this));
jTextField1.addActionListener(new compilateur_jTextField1_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(12, 82, 372, 200));
jLabel3.setText("Erreurs:");
jLabel3.setBounds(new Rectangle(14,290,50,24));
jScrollPane2.setBounds(new Rectangle(12, 310, 375, 100));
contentPane.add(jLabel1);
contentPane.add(jLabel2);
contentPane.add(jTextField1);
contentPane.add(jButton1);
contentPane.add(jScrollPane1);
contentPane.add(jLabel3);
contentPane.add(jScrollPane2);
jScrollPane1.getViewport().add(jTextArea1);
jScrollPane2.getViewport().add(jTextArea2);
}
public void jButton1ActionPerformed(ActionEvent e){
jTextArea1.setText("_________Debut[Compilation Test]_________\n");
try{
Scanner scanner = new Scanner(new FileInputStream(jTextField1.getText()));
scanner.next();
while(scanner.car!=ScannerTest.EOF){
jTextArea2.setText(scanner.err);
jTextArea1.append("[ligne:"+scanner.ligne+"]");
jTextArea1.append(ScannerTest.representation(scanner.car));
if((scanner.car==ScannerTest.CHF)||
(scanner.car==ScannerTest.ID)||
(scanner.car==ScannerTest.PLUS)||
(scanner.car==ScannerTest.MOINS)||
(scanner.car==ScannerTest.MULT)||
(scanner.car==ScannerTest.DIV)||
(scanner.car==ScannerTest.DEC_DR)||
(scanner.car==ScannerTest.DEC_GH)||
(scanner.car==ScannerTest.INF)||
(scanner.car==ScannerTest.SUP)||
(scanner.car==ScannerTest.EGL)||
(scanner.car==ScannerTest.SUP_EGL)||
(scanner.car==ScannerTest.INF_EGL)||
(scanner.car==ScannerTest.DIF)||
(scanner.car==ScannerTest.AFF)||
(scanner.car==ScannerTest.NON_LOG)||
(scanner.car==ScannerTest.ET_LOG)||
(scanner.car==ScannerTest.OU_LOG)||
(scanner.car==ScannerTest.IF)||
(scanner.car==ScannerTest.FI)||
(scanner.car==ScannerTest.FLT)||
(scanner.car==ScannerTest.WR)||
(scanner.car==ScannerTest.RD)||
(scanner.car==ScannerTest.STR)||
(scanner.car==ScannerTest.ELSE)||
(scanner.car==ScannerTest.BOL)||
(scanner.car==ScannerTest.UNT)||
(scanner.car==ScannerTest.FL)||
(scanner.car==ScannerTest.INT)||
(scanner.car==ScannerTest.TR)||
(scanner.car==ScannerTest.RPT)||
(scanner.car==ScannerTest.WLE)||
(scanner.car==ScannerTest.ELW)){
jTextArea1.append("("+scanner.chars+")\n");
}else{
jTextArea1.append("\n");
}
scanner.next();
}
scanner.close();
}catch(IOException ex){
//jTextArea1.append(ex);
System.exit(-1);
}
jTextArea1.append("______Fin [Compilation Test]______/n");
}
public void jTextField1ActionPerformed(ActionEvent e){

}
}
class compilateur_jTextField1_actionAdapter implements ActionListener{
private compilateur adaptee;
compilateur_jTextField1_actionAdapter(compilateur adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.jTextField1ActionPerformed(e);
}
}
class compilateur_jButton1_actionAdapter implements ActionListener{
private compilateur adaptee;
compilateur_jButton1_actionAdapter(compilateur adapte){
this.adaptee=adaptee;
}

public void actionPerformed(ActionEvent e){
175: adaptee.jButton1ActionPerformed(e);
}

}
should i initialize variable : adaptee? & how?

1 réponse

Messages postés
15781
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
8 avril 2021
529
Bonjour

CodeS SourceS est un forum francophone, soit
  • tu écris en français
  • tu vas poster ta question sur le forum anglophone du groupe ccm.net


Ensuite, ici ou là bas, pour poster un code il faut faire comme décrit là https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Une fois ces 2 conditions remplies, on pourra commencer à essayer de t'aider


Quand j'étais petit, la mer Morte n'était que malade.
George Burns