我将图像设置为我的 JApplet 的背景,并使用调整大小的方法将图像填充到 JApplet 背景中。我目前正在使用
Image background;
public void paint(Graphics g) {
super.paint(g);
g.drawImage(background, 0, 0, this);
}
public void init() {
// TODO start asynchronous download of heavy resources
background=resize(new ImageIcon(getClass().getResource("/org/me/pd/resources/music.png")),this.getWidth(),this.getHeight()).getImage();
this.setLayout(new GridLayout(6,6));
//Create();
}
这是我的调整大小方法
public ImageIcon resize(ImageIcon icon, int width, int height)
{
BufferedImage converted = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = converted.createGraphics();
icon.paintIcon(null, g, 0,0);
g.dispose();
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
Graphics2D g2d = (Graphics2D) bi.createGraphics();
g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
g2d.drawImage(converted, 0, 0, width, height, null);
g2d.dispose();
ImageIcon correct=new ImageIcon(bi);
return correct;
}
这最初在加载小程序并填充图像时起作用,但是当小程序最大化时,图像不会随小程序最大化。它显示了最大化之前的状态。
我究竟做错了什么?