- import javax.swing.*;
- import java.awt.*;
- public class TestImageIcon extends JFrame{
- private ImageIcon usIcon=new ImageIcon("image/us.gif");
- private ImageIcon myIcon=new ImageIcon("imgae/my.jpg");
- private ImageIcon frIcon=new ImageIcon("image/fr.gif");
- private ImageIcon ukIcon=new ImageIcon("imgae/uk.gif");
-
- public TestImageIcon(){
- setLayout(new GridLayout(1,2,5,5));
- add(new JLabel(usIcon));
- add(new JLabel(myIcon));
- add(new JButton(frIcon));
- add(new JButton(ukIcon));
- }
- public static void main(String[] args) {
- TestImageIcon frame = new TestImageIcon();
- frame.setTitle("TestImageIcon");
- frame.setSize(200,200);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- }
复制代码 |