Que pasa con mi prog?
Publicado por mauricio Alejandro Peralta Bau (2 intervenciones) el 19/09/2006 01:49:03
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
public class grise1 extends Applet {
Image img = null, imge = null;
int iw, ih;
int pixels [], pixel = 0;
int mat [][];
TextField nimagen = new TextField (17);
String Cad = "";
public void init(){
add (new Label ("Dame la imagen a cargar"));
add (nimagen);
add(new Button ("O.K."));
}
boolean lee (String cad) {
// Carga imagen y la deja en una matriz
boolean b = true;
try {
int kk=0;
img= getImage(getCodeBase(), cad);
do{
Thread.sleep(100);
iw = img.getWidth (this);
ih = img.getHeight (this);
System.out.println ("wi="+iw+" ");
kk++;
}
while (iw == -1 && kk < 50);
if (iw > 0){
pixels = new int [iw * ih];
mat = new int [ih][iw];
PixelGrabber pg = new PixelGrabber (img, 0, 0, iw, ih, pixels, 0, iw);
pg.grabPixels();
}
else b = false;
} catch (InterruptedException e) {b = false;};
return b;
}
public boolean action (Event ev, Object o) {
String cad;
if (ev.target instanceof Button) {
cad = nimagen.getText();
if (lee (cad))
transforma ();
repaint ();
return true;
}
return false;
}
void transforma() {
int i=0;
System.out.println("Transforma");
for (int x=0; x<ih; x++)
for (int y=0; y<iw; y++) {
int p = pixels[i];
int r = 0xff & (p >> 16);
int g = 0xff & (p >> 8);
int b = 0xff & (p);
mat [x][y] = (int)((double)(r+g+b)/3.0);
i++;
}
// transforma la matriz a imagen
imge = transforma (mat, iw, ih);
}
Image transforma (int mat[][], int an, int al) {
int i=0, c;
Image sal;
int pixles[] = new int [an * al];
for (int x=0; x<al; x++){
for (int y=0; y<an; y++){
c=mat[x][y];
pixles[i]=(255 << 24)|(c << 16)|(c << 8)|c;
i++;
}
}
sal = createImage (new MemoryImageSource (an, al, pixles ,0 , an));
return sal;
}
public void paint (Graphics g) {
if (imge != null){
g.drawImage (img, 10, 40, this);
g.drawImage (imge, 410, 40, this);
}
}
}
DESPUES DE ESO ME CREA EL . CLASS, PERO EL PROBLEMA ESTA A LA HORA DE QUERERLO CORRER. ME MANDA EL SIGUIENTE ERROR:
----jGRASP exec: java grise1
Exception in thread "main" java.lang.NoSuchMethodError: main
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
COMO PUEDEN VER ESTOY TRABAJANDO EN JGRASP, SI ALGUIEN PUEDE AYUDARME A RESOLVERLO SE LO AGREDECERE MUCHO
import java.awt.*;
import java.awt.image.*;
public class grise1 extends Applet {
Image img = null, imge = null;
int iw, ih;
int pixels [], pixel = 0;
int mat [][];
TextField nimagen = new TextField (17);
String Cad = "";
public void init(){
add (new Label ("Dame la imagen a cargar"));
add (nimagen);
add(new Button ("O.K."));
}
boolean lee (String cad) {
// Carga imagen y la deja en una matriz
boolean b = true;
try {
int kk=0;
img= getImage(getCodeBase(), cad);
do{
Thread.sleep(100);
iw = img.getWidth (this);
ih = img.getHeight (this);
System.out.println ("wi="+iw+" ");
kk++;
}
while (iw == -1 && kk < 50);
if (iw > 0){
pixels = new int [iw * ih];
mat = new int [ih][iw];
PixelGrabber pg = new PixelGrabber (img, 0, 0, iw, ih, pixels, 0, iw);
pg.grabPixels();
}
else b = false;
} catch (InterruptedException e) {b = false;};
return b;
}
public boolean action (Event ev, Object o) {
String cad;
if (ev.target instanceof Button) {
cad = nimagen.getText();
if (lee (cad))
transforma ();
repaint ();
return true;
}
return false;
}
void transforma() {
int i=0;
System.out.println("Transforma");
for (int x=0; x<ih; x++)
for (int y=0; y<iw; y++) {
int p = pixels[i];
int r = 0xff & (p >> 16);
int g = 0xff & (p >> 8);
int b = 0xff & (p);
mat [x][y] = (int)((double)(r+g+b)/3.0);
i++;
}
// transforma la matriz a imagen
imge = transforma (mat, iw, ih);
}
Image transforma (int mat[][], int an, int al) {
int i=0, c;
Image sal;
int pixles[] = new int [an * al];
for (int x=0; x<al; x++){
for (int y=0; y<an; y++){
c=mat[x][y];
pixles[i]=(255 << 24)|(c << 16)|(c << 8)|c;
i++;
}
}
sal = createImage (new MemoryImageSource (an, al, pixles ,0 , an));
return sal;
}
public void paint (Graphics g) {
if (imge != null){
g.drawImage (img, 10, 40, this);
g.drawImage (imge, 410, 40, this);
}
}
}
DESPUES DE ESO ME CREA EL . CLASS, PERO EL PROBLEMA ESTA A LA HORA DE QUERERLO CORRER. ME MANDA EL SIGUIENTE ERROR:
----jGRASP exec: java grise1
Exception in thread "main" java.lang.NoSuchMethodError: main
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
COMO PUEDEN VER ESTOY TRABAJANDO EN JGRASP, SI ALGUIEN PUEDE AYUDARME A RESOLVERLO SE LO AGREDECERE MUCHO
Valora esta pregunta


0