一个老问题了,窗口背景图不显示
以前弄过,忘了。谁给看下,怎么解决?背景不显示,源码如下:
public class MyDialog extends JDialog {
MyDialog(int x,int y)
{
setTitle("关于 计算器");
setLayout(null);
setSize(200, 200);
setLocation(x,y);
setModal(true);
setVisible(true);
}
public void paintComponents(Graphics g) {
super.paintComponents(g);
ImageIcon icon=new ImageIcon("winxp.gif");
g.drawImage(icon.getImage(), 0,0,this);
}
}
------解决方案--------------------
public void paintComponents(Graphics g) {
super.paintComponents(g);
不应该重写这个方法,应该是
public void paintComponent(Graphics g) {
super.paintComponent(g);