java用户界面——加载图片 jpg GIF

java用户界面——加载图片 jpg GIF 

代码如下:

package day08;

import java.awt.GridLayout;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Testdongyaidujiazai extends JFrame {
private Icon image1 = new ImageIcon("01.jpg");
// private Icon image2 = new ImageIcon("02.jpg");
// private Icon image3 = new ImageIcon("03.jpg");
public Testdongyaidujiazai(){
setLayout(new GridLayout(1,4));
add(new JLabel(image1));
// add(new JLabel(image2));
// add(new JLabel(image3));
//
}
public static void main(String[] args){
Testdongyaidujiazai test = new Testdongyaidujiazai();
test.setSize(500,500);
test.setLocationRelativeTo(null);
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setVisible(true);
}
}