ecrire une methode aves des classes imbriquées
Bonjour,
Je bloque sur ma méthode qui me donne une erreur à la compilation,j'ai crée une class avec un tableau d'images, je cherche à récupérer le nom de mes images qui se trouve dans une autre class puis en faire une liste:
l'erreur est à ligne:
Collection.java:50: ')' expected
this.mesImagesLues[j]=new Bitmap(String n);
je suis pas sûr d'avoir bien fait pour récupérer le nom de l'image
Merci de votre aide.
ma collection d'images :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import java.io.*;
import java.util.Scanner;
public class Collection {
Scanner sc = new Scanner(System.in);
Bitmap []mesImagesLues;
int nbImagesLues=0;
Bitmap []mesImagesCrees;
int nbImagesCrees=0;
Collection(){ //constructeur
Bitmap []mesImagesLues=new Bitmap[0];
this.nbImagesLues=0;
Bitmap []mesImagesCrees=new Bitmap[0];
this.nbImagesCrees=0;
}
void ajouterImageLues(Bitmap A){
Bitmap []ImgLuesNv=new Bitmap[mesImagesLues.length + 1];
for (int i=0; i<mesImagesLues.length; i++)
ImgLuesNv[i]=mesImagesLues[i];
ImgLuesNv[mesImagesLues.length]=A;
mesImagesLues=ImgLuesNv;
}
void ajouterImageCrees(Bitmap X){
Bitmap []ImgCreesNv=new Bitmap[mesImagesCrees.length + 1];
for (int i=0; i<mesImagesCrees.length; i++)
ImgCreesNv[i]=mesImagesCrees[i];
ImgCreesNv[mesImagesCrees.length]=X;
mesImagesCrees=ImgCreesNv;
}
void supprimerImageLues(){
System.out.println("Quelle image voulez-vous supprimer ?");
int Ind=sc.nextInt();
int IndSup=Ind-1;
Bitmap []ImgLuesNv=new Bitmap[mesImagesLues.length - 1];
for( int i=0;i<IndSup;i++)
ImgLuesNv[i]=mesImagesLues[i];
for( int i=0;i<ImgLuesNv.length-IndSup;i++)
ImgLuesNv[i+IndSup]=mesImagesLues[i+(IndSup+1)];
mesImagesLues=ImgLuesNv;
}
Collection saisirCollection(){
for(int j=0;j<this.mesImagesLues.length;j++){
this.mesImagesLues[j]=new Bitmap(String n); //erreur à la compil pourtant je respecte le constructeur Bitmap
this.mesImagesLues[j].ie=new ImageExterneLue(n);
}
return this;
}
void afficherCollection(){
System.out.println("liste d'images");
for(int i=0;i<mesImagesLues.length;i++){
System.out.println( (i+1)+ "- ");
mesImagesLues[i].saisiCollection();
}
}
} |
ma class Images:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import java.io.*;
import java.util.Scanner;
public class Bitmap {
Scanner sc = new Scanner(System.in);
int[][][]data;
String nom;
ImageExterne ie;
Bitmap(String n) throws IOException, FileNotFoundException { // constructeur pour les images lues
this.ie=new ImageExterneLue(n);
this.nom=n;
this.data=((ImageExterneLue)ie).getTableau();
}
Bitmap(int largeur, int hauteur){ // constructeur pour les images créés
this.data=new int[largeur][hauteur][3];
for(int x=0;x<this.data.length;x++){
for(int y=0;y<this.data[0].length;y++){
this.data[x][y][0]=250;
this.data[x][y][1]=250;
this.data[x][y][2]=250;
}
}
this.nom=null;
this.ie=new ImageExterneCree(this.data);
}
Bitmap(int largeur, int hauteur,int R,int V, int B){
this.data=new int[largeur][hauteur][3];
for(int x=0;x<this.data.length;x++){
for(int y=0;y<this.data[0].length;y++){
this.data[x][y][0]=R;
this.data[x][y][1]=V;
this.data[x][y][2]=B;
}
}
this.nom=null;
this.ie=new ImageExterneCree(this.data);
}
Bitmap creerImage(Bitmap ImgLue){ //Bitmap creerImage(Bitmap ImgLue){
this.data=ImgLue.data;
this.nom=null;
this.ie=new ImageExterneCree(this.data);
return this;
} |
et la dernière utilisée dans la class Bitmap:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
public class ImageExterneLue extends ImageExterne{
public ImageExterneLue(String nomf) throws IOException,
FileNotFoundException{
img = ImageIO.read(new File(nomf));
this.showImage();
}
public int[][][] getTableau(){
int wid, hei;
wid = img.getWidth();
hei = img.getHeight();
int[][][] res = new int[wid][hei][3];
int[] rgb = img.getRGB(0,0,wid,hei,null,0,wid);
for (int i=0; i<rgb.length; i++){
res[i%wid][i/wid][0]=rgb[i]>>16 & 0xFF;
res[i%wid][i/wid][1]=rgb[i]>>8 & 0xFF;
res[i%wid][i/wid][2]=rgb[i] & 0xFF;
}
return res;
} |