- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class Ch02 {
- private JFrame fm;
- private JLabel l;
- private ImageIcon icon;
- Ch02(){
- icon=new ImageIcon(Ch02.class.getResource("pic/01.jpg"));
-
- l=new JLabel(icon);
- l.setBounds(0, 0, 399, 300);
-
- fm=new JFrame("ImageIcon 類別");
- fm.setBounds(100, 100, 405, 328);
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setLayout(null);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.add(l);
- }
- public static void main(String[] args) {
- new Ch02();
- }
- }
複製代碼 |