import javax.swing.*; import java.awt.BorderLayout; import java.net.URL; import java.net.MalformedURLException; public class JImageIconTest3 extends JFrame{ public static void main(String[] args){ JImageIconTest3 frame = new JImageIconTest3(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(10, 10, 150, 150); frame.setTitle("^Cg"); frame.setVisible(true); } JImageIconTest3(){ URL url = null; try{ url = new URL("http://www.javadrive.jp/tutorial/imageicon/hasami.png"); }catch(MalformedURLException e){ e.printStackTrace(); } JLabel label = null; if (url != null){ ImageIcon icon = new ImageIcon(url); int iconHeight = icon.getIconHeight(); int iconWidth = icon.getIconWidth(); label = new JLabel(icon); label.setText(iconWidth + "~" + iconHeight); }else{ label = new JLabel("Not image"); } JPanel p = new JPanel(); p.add(label); getContentPane().add(p, BorderLayout.CENTER); }