返回列表 發帖
本帖最後由 李允軒 於 2016-4-23 18:02 編輯
  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.ImageIcon;
  4. import javax.swing.JButton;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.ActionEvent;
  7. public class Ch01 implements ActionListener {

  8.          private JButton bt1;
  9.          private JFrame fm;
  10.      private JLabel lb;
  11.      private ImageIcon icon_s;
  12.      private ImageIcon icon,icon1;
  13.        
  14. Ch01(){
  15.         bt1=new JButton("下一張");
  16.         bt1.addActionListener(this);
  17.         bt1.setBounds(350, 310, 100, 30);
  18.         bt1.setVisible(true);
  19.        
  20.         icon_s=new ImageIcon(Ch01.class.getResource("pic/poker_icon.png"));
  21.    
  22.         icon=new ImageIcon(Ch01.class.getResource("pic/poker"+(int)(Math.random()*53+1)+".png"));
  23.        
  24.        
  25.         lb=new JLabel(icon);
  26.         lb.setBounds(80, 10, 234,351);
  27.        
  28.         fm=new JFrame("poker");       
  29.     fm.setIconImage(icon_s.getImage());
  30.     fm.setBounds(100, 100, 500, 400);
  31.     fm.setVisible(true);
  32.         fm.setResizable(false);
  33.         fm.setLayout(null);
  34.         fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35.         fm.add(lb);
  36.         fm.add(bt1);
  37. }
  38.        
  39. public void actionPerformed(ActionEvent e){
  40.         if(e.getSource()==bt1){
  41.                 icon1=new ImageIcon(Ch01.class.getResource("pic/poker"+(int)(Math.random()*53+1)+".png"));
  42.                 lb.setIcon(icon1);
  43.         }
  44. }

  45.         public static void main(String[] args) {
  46.                 Ch01 app=new Ch01();
  47.         }

  48. }
複製代碼
كخخخخخخخخخخخخخ

TOP

返回列表