整理后可执行代码如下:
import java.awt.*;
import javax.swing.*;
public class TestBackgroundColor extends JFrame
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
TestBackgroundColor tbc = new TestBackgroundColor();
tbc.setVisible(true);
}
private JPanel imagePanel;
private ImageIcon background;
public TestBackgroundColor()
{
background = new ImageIcon("渐变背景14.png");//背景图片
JLabel label = new JLabel(background);//把背景图片显示在一个标签里面
//把标签的大小位置设置为图片刚好填充整个面板
label.setBounds(0,0,background.getIconWidth(),background.getIconHeight());