Tengo este código (no esta completo solo lo principal), la idea es que tengo una foto arriba así como titulo... al ingresar unos datos a los Text Field si se ingresa un determinado valor ejemplo 1 2 3 y al apretar Analizar quiero que salga una imagen abajo.... pero no me sale.... no se que podría tener mal... creo que estoy creando mal los métodos o las clases.
RECUERDA USAR LAS TAG'S DE CÓDIGO JAVA
import java.awt.*;
import java.awt.event.*;
public Nombre() {
imagen foto = new imagen();
imagen2 foto2 = new imagen2();
setBackground
(Color.
cyan);//Color De Fondo De La Ventana setSize(400, 400);//Tamaño De La Ventana
show();//Muestra El Frame
addWindowListener(this);//Interaccion Con Los Botones
boton1.setBounds(320, 322, 60, 20);
text1.setBounds(120, 120, 16, 20);
text2.setBounds(170, 120, 16, 20);
text3.setBounds(220, 120, 16, 20);
foto.setBounds(115, 25, 500, 500);
foto2.setBounds(115, 200, 500, 500);
boton1.addActionListener(this);
add(boton1);
add(text1);
add(text2);
add(text3);
add(foto);
}
public static void main
(String[] argv
) { }
}
}
}
}
}
}
}
imagen
= Toolkit.
getDefaultToolkit().
getImage("A.png"); if (imagen != null) {
g.drawImage(imagen, 5, 5, this);
}
}
}
class imagen2
extends Canvas {
imagen2
= Toolkit.
getDefaultToolkit().
getImage("B.png"); if (imagen2 != null) {
g.drawImage(imagen2, 5, 5, this);
}
}
}
if (e.getSource() == boton1) {
if (text1.getText().equals("1") == true && text2.getText().equals("2") == true && text3.getText().equals("3") == true)
add(foto2);
}
}
}
Algo así es el código principal sobre la imagen... obviamente tengo mas código que no pondré por que es innecesario
Me pasó algo parecido hace tiempo.
El problema fue con la extensión de la imagen, que en principio solo aceptaba JPG.
Si quieres comprobar que extensiones soporta tu VM, usa este código:
// Get list of unique supported read formats
String[] formatNames
= ImageIO.
getReaderFormatNames(); formatNames = unique(formatNames);
// e.g. png jpeg gif jpg
// Get list of unique supported write formats
formatNames = ImageIO.getWriterFormatNames();
formatNames = unique(formatNames);
// e.g. png jpeg jpg
// Get list of unique MIME types that can be read
formatNames = ImageIO.getReaderMIMETypes();
formatNames = unique(formatNames);
// e.g image/jpeg image/png image/x-png image/gif
// Get list of unique MIME types that can be written
formatNames = ImageIO.getWriterMIMETypes();
formatNames = unique(formatNames);
// e.g. image/jpeg image/png image/x-png
// Converts all strings in 'strings' to lowercase
// and returns an array containing the unique values.
// All returned values are lowercase.
for (int i=0; i<strings.length; i++) {
String name
= strings
[i
].
toLowerCase(); set.add(name);
}
}
Fuente (http://www.java-tips.org/java-se-tips/javax.imageio/how-to-list-the-image-formats-that-can-be-read-and-wr.html)
Si no nos especificas el error concreto, es un poco difícil averiguar cual es.
Un saludo