こんにちは、画像を表示するシンプルなフレームをテキストフィールドとボタンにしようとしていますが、何らかの理由でテキストフィールドが見えません.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package solverapplet;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import javax.swing.JTextField;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import sun.misc.BASE64Decoder;
public class AwtImage extends Frame{
Image img;
String base="R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==";
/*public static void main(String[] args){
AwtImage ai = new AwtImage();
}*/
public void setbase(String a){
this.base=a;
}
public void refreshimage(){
try {
BASE64Decoder decoder = new BASE64Decoder();
byte[] imgBytes = decoder.decodeBuffer(this.base);
BufferedImage bufImg = ImageIO.read(new ByteArrayInputStream(imgBytes));
//File imgOutFile = new File("newLabel.png");
//ImageIO.write(bufImg, "png", imgOutFile);
img = bufImg;
} catch (IOException ex) {
Logger.getLogger(AwtImage.class.getName()).log(Level.SEVERE, null, ex);
}
}
public AwtImage(){
super("Solve");
try {
BASE64Decoder decoder = new BASE64Decoder();
byte[] imgBytes = decoder.decodeBuffer(this.base);
BufferedImage bufImg = ImageIO.read(new ByteArrayInputStream(imgBytes));
MediaTracker mt = new MediaTracker(this);
img=bufImg;
mt.addImage(img,0);
JTextField textfield= new JTextField("Text field 2", 8);
add(textfield,"South");
setSize(400,400);
//pack();
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
dispose();
}
});
} catch (IOException ex) {
Logger.getLogger(AwtImage.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
if(img != null)
g.drawImage(img, 100, 100, this);
else
g.clearRect(0, 0, getSize().width, getSize().height);
}
}
他のクラスによってインスタンス化されます。