1 //设计图像图标 2 import javax.swing.*; 3 import java.awt.*; 4 public class TestImageIcon extends JFrame 5 { 6 private ImageIcon icon1 = new ImageIcon("ToolImages/20.gif");//"ToolImages/20.gif"为该project文件夹下的路劲 7 private ImageIcon icon2 = new ImageIcon("ToolImages/21.gif"); 8 private ImageIcon icon3 = new ImageIcon("ToolImages/22.gif"); 9 public TestImageIcon()10 {11 setLayout(new GridLayout(1,3,5,5));12 add(new JButton(icon1));13 add(new JLabel(icon2));14 add(new JButton(icon3));15 }16 public static void main(String[] agrs)17 {18 JFrame frame = new TestImageIcon();19 frame.setTitle("TestImageIcon");20 frame.setLocationRelativeTo(null);21 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);22 frame.setSize(500,300);23 frame.setVisible(true);24 }25 }