Compatibilité argument File String

sido722 Messages postés 6 Date d'inscription vendredi 9 juillet 2004 Statut Membre Dernière intervention 16 juillet 2004 - 9 juil. 2004 à 15:32
sido722 Messages postés 6 Date d'inscription vendredi 9 juillet 2004 Statut Membre Dernière intervention 16 juillet 2004 - 9 juil. 2004 à 16:51
Mon erreur

Mafenetre4.java:181: tests(java.io.File) in Mafenetre4 cannot be applied to (java.lang.String)
tests(file.getAbsolutePath());
^
L'erreur est entouré de ***********************************************************************************
Mon programme

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.filechooser.*;
import java.io.*;
import java.util.StringTokenizer;

class Mafenetre4 extends JFrame implements ActionListener{

//GrapheEvent trace = new GrapheEvent(this);

JFileChooser fc = new JFileChooser();

JPanel row0 = new JPanel();
JLabel debut = new JLabel("Bienvenue au LCP-GRAPHEUR :");
// définition de la première ligne
JPanel row1 = new JPanel();
JLabel fichierLabel = new JLabel("Nom du Fichier :",JLabel.LEFT);
JTextField fichier = new JTextField(JLabel.LEFT);
// définition de la première ligne bis
JPanel row1b = new JPanel();
JButton okButton = new JButton("OK");
JTextArea fichierarea = new JTextArea(10, 20);
// définition de la deuxième ligne
JPanel row2 = new JPanel();
ButtonGroup option = new ButtonGroup();
JCheckBox courbe = new JCheckBox("Courbe", true);
JCheckBox surf = new JCheckBox("Surface", false);
// définition de la troisième ligne
JPanel row3 = new JPanel();
JLabel nbcLabel = new JLabel(" Nombre de courbes", JLabel.RIGHT);
JTextField nbcourbes = new JTextField();

//Mafenetre4 mafen;
//System.out.println(GrapheEvent);
//public void actionPerformed(ActionEvent event){}
//GrapheEvent(Mafenetre4 in){ //constructeur
//mafen = in;

public void tests(File f) throws IOException {
String texte = "";
String it = "";
String enteteputative = "";
String debentete = "== titre ==";
String finentete = "== debut ==";
double va[] = new double[100000];
int a = 0;

BufferedReader li = new BufferedReader(new FileReader(f));
enteteputative = li.readLine();

if (enteteputative.equals(debentete)) {
System.out.println("titre conforme \n" + enteteputative);
// affiche conformité et entete titre
} else { System.out.println("titre non conforme \n" +
enteteputative); }

while(!texte.equals(finentete))
{
//System.out.println(texte);
texte = li.readLine();
//System.out.println(texte);
if (texte.equals(finentete)) { break;}
Traitement(texte);
//texte = li.readLine();// + "\n";
System.out.println(texte);
}

//System.out.println(texte);
while (texte != null)
{
texte = li.readLine();
if (texte == null) {
System.out.println(finentete); break;}
//System.out.println(texte);
StringTokenizer st = new StringTokenizer(texte, " ");
while (st.hasMoreTokens()) {
it = st.nextToken();
va[a] = Double.parseDouble(it);
a++;
//System.out.println(va);
}
}

li.close();
a = a - 1;
System.out.println(va[a]);

} // fin if

public static void Traitement(String li) {

//System.out.println("ds traitement");
int pos = 0;
pos = li.indexOf("=");
String spefi = "";
String valeur = "";
int ind_x[] = {'0', '0', '0', '0'};
int dim_x[] = {'0', '0', '0', '0'};
int ndim;
int nbcol;
char c; // indices temporaire des ind_x et dim_x
String label;//titre
String tlabel[] = new String[4];//initialisation
int k;

if (pos != -1) {

if (pos < li.length()) {
int tailleli = li.length();// longueur de la ligne
//System.out.println(tailleli);spefi li.substring(0, pos-1);// sous chaine avant ss espace
//System.out.println(spefi);valeur li.substring(pos+2, tailleli);// sous chaine ap ss espac
//System.out.println(valeur);

if (spefi.equals("ndim")) { // on a trouve ndim
ndim = Integer.parseInt(valeur);// converti ssch droite int
//System.out.println("ds if ndim "+ ndim);
}
else if (spefi.equals("nbcol")) {
nbcol = Integer.parseInt(valeur);
//System.out.println("ds if nbcol "+ nbcol);
}

else if (spefi.startsWith("ind_x")) { // ssch commence par "
c = spefi.charAt(6);// recupere 7eme caractere 6+1
int intc = (int)c;// converti en int
intc = intc - 48; //char 'A';
//System.out.println("c= "+c +"= "+ intc);
ind_x[intc] = Integer.parseInt(valeur);
System.out.println("ind_x(c) "+ ind_x[intc]);

}

else if (spefi.startsWith("dim_x")) {
c = spefi.charAt(6);
int intc = (int)c;
intc = intc - 48;
dim_x[intc] = Integer.parseInt(valeur);
System.out.println("dim_x "+ dim_x[intc]);
}

else if (spefi.equals("label")) {
label = valeur;
System.out.println("label "+ valeur);
}

else if (spefi.startsWith("label(")) {
c = spefi.charAt(6);
int intc = (int)c;
//System.out.println("c intc"+c+" "+intc);
intc = intc - 48;
//System.out.println("c= "+c+" "+intc);
tlabel[intc] = valeur;
System.out.println("tlabel( "+ valeur);
}

} // FIN IF LI.LENGTH
} // FIN IF POS

// cohérence de l'entête
for (k = 0; k < 4; k++){
if (((ind_x[k]== 0) && (dim_x[k]!= 0))||((ind_x[k]!= 0)
&& (dim_x[k]== 0)))
System.out.println("L'entete de votre fichier est mal défini");
}

} // fin Traitement de l'entete

public void actionPerformed(ActionEvent event){
if (event.getSource() == okButton){
System.out.println("fichier channely");
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
System.out.println("fichier channely");
fichierarea.append("Opening: " + file.getName() + ".");
***********tests(file.getAbsolutePath());*********************************************************************

} // fin showopen
} // fin getsource
//String commande = event.getActionCommand();
// if (commande == "channely2"){
//champ.getText("chan"));
} // fin actionPerformed

Mafenetre4() {
super();

setTitle("LCP GRAPHEUR");
setSize(550, 300);
// setBounds(100, 100, 500, 270);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
GridLayout layout = new GridLayout(5, 1,
0, 2);
Container pane = getContentPane();
pane.setLayout(layout);

// ajout
//courbe.addItemListener();
//surf.addItemListener();

FlowLayout layout0 = new FlowLayout(FlowLayout.CENTER);// titre
row0.setLayout(layout0);
row0.add(debut);
pane.add(row0);

// caractérisation de la première ligne
GridLayout layout1 = new GridLayout(1, 1, 0, 2);
row1.setLayout(layout1);
row1.add(fichierLabel);
row1.add(fichier);
pane.add(row1);

// caractérisation de la première ligne bis
GridLayout layout1b = new GridLayout(1, 2, 0, 2);
row1b.setLayout(layout1b);
row1b.add(okButton);
fichierarea.setEditable(false);
row1b.add(fichierarea);
pane.add(row1b);

// caractérisation de la deuxière ligne
FlowLayout layout2 = new FlowLayout(FlowLayout.LEFT,0, 2);

option.add(courbe);
option.add(surf);
row2.setLayout(layout2);
row2.add(courbe);
row2.add(surf);
pane.add(row2);
// caractérisation de la troisière ligne

GridLayout layout3 = new GridLayout(1, 2, 5, 2);
row3.setLayout(layout3);
row3.add(nbcLabel);
row3.add(nbcourbes);
pane.add(row3);
setContentPane(pane);
setVisible(true);

okButton.addActionListener(this);
//addItemListener(this);
}
//import javax.swing.*;
//import java.awt.event.*;
//public class GrapheEvent implements ItemListener, ActionListener{
//Thread playing;
//}

//class Essai{
public static void main(String[] argv) {
Mafenetre4 badou = new Mafenetre4();
//badou.setContentPane(new Mafenetre4());

//}
}
}
Merci
sido :)

2 réponses

wargre Messages postés 649 Date d'inscription mardi 8 juin 2004 Statut Membre Dernière intervention 9 septembre 2004 7
9 juil. 2004 à 15:49
met test(file.getAbsoluteFile() et pas test.getAbsolutePath()
0
sido722 Messages postés 6 Date d'inscription vendredi 9 juillet 2004 Statut Membre Dernière intervention 16 juillet 2004
9 juil. 2004 à 16:51
resolu j'ai mis juste
try{
tests(file);
}
catch(IOException e) {}
ca marche
sido :big)
0
Rejoignez-nous