返回列表 發帖

ImageIcon 類別 (一)

本帖最後由 tonyh 於 2021-8-6 11:36 編輯

試利用 javax.swing 套件下的 ImageIcon 類別, 在視窗中置入圖片.

[設計導引]
1. 視窗的 左、右、下方 的邊框佔 3 像素 ; 上方的標題列佔 25 像素
     ( setResizable() 方法的參數設為 false 所展現的數據 )
2. 圖片大小 399x300 ; 標籤大小 399x300 ; 視窗大小 405x328

  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;
  4. public class Ch87 {
  5.        
  6.         private JFrame fm;
  7.         private JLabel lb;
  8.         private ImageIcon icon;
  9.        
  10.         Ch87()
  11.         {
  12.                 icon=new ImageIcon(Ch87.class.getResource("pic/01.jpg"));

  13.                 //lb=new JLabel(new ImageIcon(Ch87.class.getResource("pic/01.jpg")));
  14.                 lb=new JLabel(icon);
  15.                 lb.setBounds(0, 0, 399, 300);
  16.                
  17.                 fm=new JFrame("ImageIcon 類別");
  18.                 fm.setBounds(100, 100, 405, 328);
  19.                 fm.setVisible(true);
  20.                 fm.setResizable(false);
  21.                 fm.setLayout(null);
  22.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23.                 fm.add(lb);       
  24.         }
  25.                
  26.         public static void main(String[] args) {
  27.                 Ch87 app=new Ch87();
  28.         }
  29. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;
  4. public class Ch87 {
  5.         
  6.         private JFrame fm;
  7.         private JLabel lb;
  8.         private ImageIcon icon;
  9.         
  10.         Ch87()
  11.         {
  12.                 icon=new ImageIcon(Ch87.class.getResource("pic/01.jpg"));

  13.                 //lb=new JLabel(new ImageIcon(Ch87.class.getResource("pic/01.jpg")));
  14.                 lb=new JLabel(icon);
  15.                 lb.setBounds(0, 0, 399, 300);
  16.                
  17.                 fm=new JFrame("ImageIcon 類別");
  18.                 fm.setBounds(100, 100, 405, 328);
  19.                 fm.setVisible(true);
  20.                 fm.setResizable(false);
  21.                 fm.setLayout(null);
  22.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23.                 fm.add(lb);        
  24.         }
  25.                
  26.         public static void main(String[] args) {
  27.                 Ch87 app=new Ch87();
  28.         }
  29. }
複製代碼
高睿辰是幹話之王

TOP

  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;
  4. public class Ch87 {
  5.         
  6. private JFrame fm;
  7. private JLabel lb;
  8. private ImageIcon icon;
  9.         
  10. Ch87()
  11. {
  12.                 icon=new ImageIcon(Ch87.class.getResource("pic/01.jpg"));
  13.                 lb=new JLabel(icon);
  14.                 lb.setBounds(0, 0, 399, 300);  
  15.                 fm=new JFrame("ImageIcon 類別");
  16.                 fm.setBounds(100, 100, 405, 328);
  17.                 fm.setVisible(true);
  18.                 fm.setResizable(false);
  19.                 fm.setLayout(null);
  20.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.                 fm.add(lb);        
  22. }
  23.                
  24. public static void main(String[] args) {
  25.                                 Ch87 app=new Ch87();
  26.         }
  27. }
複製代碼
七日不見 如隔一周

TOP

  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;
  4. public class Ch87 {
  5.         
  6.         private JFrame fm;
  7.         private JLabel lb;
  8.         private ImageIcon icon;
  9.         
  10.         Ch87()
  11.         {
  12.                 icon=new ImageIcon(Ch87.class.getResource("pic/01.jpg"));

  13.                 //lb=new JLabel(new ImageIcon(Ch87.class.getResource("pic/01.jpg")));
  14.                 lb=new JLabel(icon);
  15.                 lb.setBounds(0, 0, 399, 300);
  16.                
  17.                 fm=new JFrame("ImageIcon 類別");
  18.                 fm.setBounds(100, 100, 405, 328);
  19.                 fm.setVisible(true);
  20.                 fm.setResizable(false);
  21.                 fm.setLayout(null);
  22.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23.                 fm.add(lb);        
  24.         }
  25.                
  26.         public static void main(String[] args) {
  27.                 Ch87 app=new Ch87();
  28.         }
  29. }
複製代碼
一年不見,如隔四季

TOP

  1. import javax.swing.ImageIcon;
  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;


  4. public class Ch87 {

  5.         JFrame fm;
  6.         JLabel lb;
  7.         ImageIcon ic;
  8.        
  9.         Ch87()
  10.         {
  11.                 ic=new ImageIcon(Ch87.class.getResource("pic/01.jpg"));
  12.                
  13.                 lb=new JLabel(ic);
  14.                 lb.setBounds(0, 0, 399, 300);
  15.                
  16.                 fm=new JFrame("ImageIcon 練習");
  17.                 fm.setBounds(100, 100, 405, 328);
  18.                 fm.setVisible(true);
  19.                 fm.setResizable(false);
  20.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.                 fm.setLayout(null);
  22.                 fm.add(lb);
  23.         }
  24.        
  25.        
  26.         public static void main(String[] args) {
  27.                 new Ch87();
  28.         }
  29. }
複製代碼

TOP

  1. import javax.swing.ImageIcon;
  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;


  4. public class Ch87 {
  5.        
  6.         JFrame fm;
  7.         JLabel lb;
  8.         ImageIcon ic;
  9.        
  10.         Ch87()
  11.         {
  12.                
  13.                 ic=new ImageIcon(Ch87.class.getResource("pic/01 (2).jpg"));
  14.                
  15.                 lb=new JLabel(ic);
  16.                 lb.setBounds(0,0,399,300);
  17.                
  18.                
  19.                
  20.                 fm=new JFrame("ImageIcon Practice");
  21.                 fm.setBounds(100, 100, 405, 328);
  22.                 fm.setVisible(true);
  23.                 fm.setResizable(false);
  24.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.                 fm.setLayout(null);
  26.                 fm.add(lb);
  27.                                
  28.         }
  29.         public static void main(String[] args) {
  30.                 new Ch87();

  31.         }

  32. }
複製代碼

TOP

  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;
  4. public class Ch87 {
  5.         
  6.         private JFrame fm;
  7.         private JLabel lb;
  8.         private ImageIcon icon;
  9.         
  10.         Ch87() {
  11.                 icon=new ImageIcon(Ch87.class.getResource("pic/01.jpg"));

  12.                 lb=new JLabel(icon);
  13.                 lb.setBounds(0, 0, 399, 300);
  14.                
  15.                 fm=new JFrame("ImageIcon 類別");
  16.                 fm.setBounds(100, 100, 405, 328);
  17.                 fm.setVisible(true);
  18.                 fm.setResizable(false);
  19.                 fm.setLayout(null);
  20.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.                 fm.add(lb);        
  22.         }
  23.                
  24.         public static void main(String[] args) {
  25.                 Ch87 app=new Ch87();
  26.         }
  27. }
複製代碼

TOP

返回列表