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显示图片了,哪里来的那些麻烦事