首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

JPanel 插入图片有关问题

2012-02-20 
JPanel 插入图片问题import javax.swing.*import java.awt.*public class Test extends JFrame{ImageIco

JPanel 插入图片问题
import javax.swing.*;

import java.awt.*;

public class Test extends JFrame{

ImageIcon icon;
JPanel jp1;
public Test()
{
this.add(buildWestJpanel());
this.setSize(350,350);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public JPanel buildWestJpanel()
{
jp1 = new JPanel();
if(icon ==null)
{
icon = new ImageIcon("login.gif");
}
jp1.repaint();
return jp1;
}
protected void paintComponent(Graphics g) {
super.paintComponents(g);
g.drawImage(icon.getImage(),0,0,350,89,jp1);
  }
public static void main(String args[])
{
new Test();
}
}

为什么这段代码不能把login.gif插入进去,也就是我运行不显示图片

[解决办法]
直接使用JLabel显示图片了,哪里来的那些麻烦事

热点排行