Aidez moi svp je ne trouve pas l'erreur JAVA
ylleria
Messages postés
25
Date d'inscription
Statut
Membre
Dernière intervention
-
ylleria Messages postés 25 Date d'inscription Statut Membre Dernière intervention -
ylleria Messages postés 25 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
le programe doit faire une analyse syntaxique d'un fichier texte comme sui :
ex:12,15 , 14 .
des nombre separé par des blanc est fini par un point
mé regardé quand japui sur le button compilé qui doi faite lanalyse rien ne se passe
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.swing.*;
import java.util.Vector;
public class TPparadigme extends JApplet {
JLabel label_1;
JLabel label_2;
JTextField textfield_1;
JButton button_1;
JButton button_2;
JLabel label_3;
JTextField textfield_2;
JButton button_3;
JButton button_4;
ArrayList<Integer> liste = new ArrayList<Integer>(5);
public void init() {
TPparadigmeLayout customLayout = new TPparadigmeLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
getContentPane().setLayout(customLayout);
setBackground(Color.LIGHT_GRAY);
label_1 = new JLabel("Soyez les bienvenus");
getContentPane().add(label_1);
label_2 = new JLabel("Votre Fichier");
getContentPane().add(label_2);
textfield_1 = new JTextField("Votre fichier ICI");
getContentPane().add(textfield_1);
button_1 = new JButton("Parcourir");
getContentPane().add(button_1);
button_1.addActionListener(new TPparadigme_button_1_actionAdapter(this));
button_2 = new JButton("Compiler");
getContentPane().add(button_2);
button_2.addActionListener(new TPparadigme_button_2_actionAdapter(this));
label_3 = new JLabel("L'élem à cherhé");
getContentPane().add(label_3);
textfield_2 = new JTextField("L'élement à chercher ICI");
getContentPane().add(textfield_2);
button_3 = new JButton("Chercher");
getContentPane().add(button_3);
button_3.addActionListener(new TPparadigme_button_3_actionAdapter(this));
button_4 = new JButton("Quitter");
getContentPane().add(button_4);
button_4.addActionListener(new TPparadigme_button_4_actionAdapter(this));
setSize(getPreferredSize());
}
// bouton 1 parcourire
public void button_1_actionPerformed(ActionEvent e){
JFileChooser choix = new JFileChooser();
int retour = choix.showOpenDialog(button_1);
if (retour == JFileChooser.APPROVE_OPTION) {
// un fichier a été choisi (sortie par Ouvrir)
choix.getSelectedFile().getName();// nom du fichier choisi
choix.getSelectedFile().getAbsolutePath();// chemin absolu du fichier choisi
}
textfield_1.setText(choix.getSelectedFile().getAbsolutePath());
}
class TPparadigme_button_1_actionAdapter implements ActionListener{
private TPparadigme adaptee;
TPparadigme_button_1_actionAdapter(TPparadigme adaptee){
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.button_1_actionPerformed(e);
}
}
// bouton 2 Complier
public void button_2_actionPerformed(ActionEvent e){
String s="",s2="";
Pattern p = Pattern.compile("(\\s*[0-9]+\\s*,)*\\s*[0-9]+\\s*.");
try
{
FileReader fr = new FileReader(textfield_1.getText()) ;
BufferedReader br = new BufferedReader ( fr ) ;
String ligne = br.readLine() ;
while ( ligne != null ){
Matcher m = p.matcher(ligne);
ligne = ligne.replaceAll("\\s", "");//eliminer les espaces de la ligne
s=s+ligne;
}
br.close( ) ;//fermer le fichier
}catch ( FileNotFoundException exp){
javax.swing.JOptionPane.showConfirmDialog(null,
" Erreur!!Fichier Introuvable.",
"Erreur de Lecture",
javax.swing.JOptionPane.PLAIN_MESSAGE);
return;
}
catch ( IOException exp ){
javax.swing.JOptionPane.showConfirmDialog(null,
"Erreur!!Probléme a la lecture du fichier.",
"Erreur",
javax.swing.JOptionPane.PLAIN_MESSAGE);
return;
}
catch (PatternSyntaxException exp){
javax.swing.JOptionPane.showConfirmDialog(null,
"Erreur!!Verifier la gramaire de votre texte.",
"Erreur dans la gramaire",
javax.swing.JOptionPane.PLAIN_MESSAGE);
return;
}
StringTokenizer st1=new StringTokenizer(s,",");
Arbre X=new Arbre();
if (st1.hasMoreTokens()) {
s2=st1.nextToken().trim();
int monEntier = Integer.parseInt(s2);
X.setNode(monEntier);
}
while (st1.hasMoreTokens())
{
s2=st1.nextToken().trim();
int Nbr=Integer.parseInt(s2);
X.addChild(Nbr);
}
}
class TPparadigme_button_2_actionAdapter implements ActionListener{
private TPparadigme adaptee;
TPparadigme_button_2_actionAdapter(TPparadigme adaptee){
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.button_2_actionPerformed(e);
}
}
public static void main(String args[]) {
TPparadigme applet = new TPparadigme();
JFrame window = new JFrame("TPparadigme");
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
applet.init();
window.getContentPane().add("Center", applet);
window.pack();
window.setVisible(true);
}
}
class TPparadigmeLayout implements LayoutManager {
public TPparadigmeLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 521 + insets.left + insets.right;
dim.height = 330 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+32,272,32);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+112,104,24);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+112,104,24);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+112,88,24);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+160,104,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+216,104,24);}
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+216,104,24);}
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+216,88,24);}
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+232,insets.top+280,88,24);}
}
}
le programe doit faire une analyse syntaxique d'un fichier texte comme sui :
ex:12,15 , 14 .
des nombre separé par des blanc est fini par un point
mé regardé quand japui sur le button compilé qui doi faite lanalyse rien ne se passe
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.swing.*;
import java.util.Vector;
public class TPparadigme extends JApplet {
JLabel label_1;
JLabel label_2;
JTextField textfield_1;
JButton button_1;
JButton button_2;
JLabel label_3;
JTextField textfield_2;
JButton button_3;
JButton button_4;
ArrayList<Integer> liste = new ArrayList<Integer>(5);
public void init() {
TPparadigmeLayout customLayout = new TPparadigmeLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
getContentPane().setLayout(customLayout);
setBackground(Color.LIGHT_GRAY);
label_1 = new JLabel("Soyez les bienvenus");
getContentPane().add(label_1);
label_2 = new JLabel("Votre Fichier");
getContentPane().add(label_2);
textfield_1 = new JTextField("Votre fichier ICI");
getContentPane().add(textfield_1);
button_1 = new JButton("Parcourir");
getContentPane().add(button_1);
button_1.addActionListener(new TPparadigme_button_1_actionAdapter(this));
button_2 = new JButton("Compiler");
getContentPane().add(button_2);
button_2.addActionListener(new TPparadigme_button_2_actionAdapter(this));
label_3 = new JLabel("L'élem à cherhé");
getContentPane().add(label_3);
textfield_2 = new JTextField("L'élement à chercher ICI");
getContentPane().add(textfield_2);
button_3 = new JButton("Chercher");
getContentPane().add(button_3);
button_3.addActionListener(new TPparadigme_button_3_actionAdapter(this));
button_4 = new JButton("Quitter");
getContentPane().add(button_4);
button_4.addActionListener(new TPparadigme_button_4_actionAdapter(this));
setSize(getPreferredSize());
}
// bouton 1 parcourire
public void button_1_actionPerformed(ActionEvent e){
JFileChooser choix = new JFileChooser();
int retour = choix.showOpenDialog(button_1);
if (retour == JFileChooser.APPROVE_OPTION) {
// un fichier a été choisi (sortie par Ouvrir)
choix.getSelectedFile().getName();// nom du fichier choisi
choix.getSelectedFile().getAbsolutePath();// chemin absolu du fichier choisi
}
textfield_1.setText(choix.getSelectedFile().getAbsolutePath());
}
class TPparadigme_button_1_actionAdapter implements ActionListener{
private TPparadigme adaptee;
TPparadigme_button_1_actionAdapter(TPparadigme adaptee){
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.button_1_actionPerformed(e);
}
}
// bouton 2 Complier
public void button_2_actionPerformed(ActionEvent e){
String s="",s2="";
Pattern p = Pattern.compile("(\\s*[0-9]+\\s*,)*\\s*[0-9]+\\s*.");
try
{
FileReader fr = new FileReader(textfield_1.getText()) ;
BufferedReader br = new BufferedReader ( fr ) ;
String ligne = br.readLine() ;
while ( ligne != null ){
Matcher m = p.matcher(ligne);
ligne = ligne.replaceAll("\\s", "");//eliminer les espaces de la ligne
s=s+ligne;
}
br.close( ) ;//fermer le fichier
}catch ( FileNotFoundException exp){
javax.swing.JOptionPane.showConfirmDialog(null,
" Erreur!!Fichier Introuvable.",
"Erreur de Lecture",
javax.swing.JOptionPane.PLAIN_MESSAGE);
return;
}
catch ( IOException exp ){
javax.swing.JOptionPane.showConfirmDialog(null,
"Erreur!!Probléme a la lecture du fichier.",
"Erreur",
javax.swing.JOptionPane.PLAIN_MESSAGE);
return;
}
catch (PatternSyntaxException exp){
javax.swing.JOptionPane.showConfirmDialog(null,
"Erreur!!Verifier la gramaire de votre texte.",
"Erreur dans la gramaire",
javax.swing.JOptionPane.PLAIN_MESSAGE);
return;
}
StringTokenizer st1=new StringTokenizer(s,",");
Arbre X=new Arbre();
if (st1.hasMoreTokens()) {
s2=st1.nextToken().trim();
int monEntier = Integer.parseInt(s2);
X.setNode(monEntier);
}
while (st1.hasMoreTokens())
{
s2=st1.nextToken().trim();
int Nbr=Integer.parseInt(s2);
X.addChild(Nbr);
}
}
class TPparadigme_button_2_actionAdapter implements ActionListener{
private TPparadigme adaptee;
TPparadigme_button_2_actionAdapter(TPparadigme adaptee){
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.button_2_actionPerformed(e);
}
}
public static void main(String args[]) {
TPparadigme applet = new TPparadigme();
JFrame window = new JFrame("TPparadigme");
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
applet.init();
window.getContentPane().add("Center", applet);
window.pack();
window.setVisible(true);
}
}
class TPparadigmeLayout implements LayoutManager {
public TPparadigmeLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 521 + insets.left + insets.right;
dim.height = 330 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+32,272,32);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+112,104,24);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+112,104,24);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+112,88,24);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+160,104,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+216,104,24);}
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+216,insets.top+216,104,24);}
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+216,88,24);}
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+232,insets.top+280,88,24);}
}
}
A voir également:
- Aidez moi svp je ne trouve pas l'erreur JAVA
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Pourquoi ma tv ne trouve pas toutes les chaînes - Guide
6 réponses
Lorsque tu appuies sur le bouton "compiler" ton programme effectue une boucle infinie. C'est pour cela que tu penses qu'il ne se passe rien.
L'erreur est ici :
BufferedReader br = new BufferedReader ( fr ) ;
String ligne = br.readLine() ;
while ( ligne != null ){
ligne = br.readLine();
Matcher m = p.matcher(ligne);
ligne = ligne.replaceAll("\\s", "");//eliminer les espaces de la ligne
s=s+ligne;
}
Tu lisais toujours la même ligne dans ton fichier au lieu de faire "avancer" le BufferedReader.
Bonne continuation
L'erreur est ici :
BufferedReader br = new BufferedReader ( fr ) ;
String ligne = br.readLine() ;
while ( ligne != null ){
ligne = br.readLine();
Matcher m = p.matcher(ligne);
ligne = ligne.replaceAll("\\s", "");//eliminer les espaces de la ligne
s=s+ligne;
}
Tu lisais toujours la même ligne dans ton fichier au lieu de faire "avancer" le BufferedReader.
Bonne continuation
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question