返回列表 發帖
  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 A90 implements ActionListener
  8. {
  9.         private JFrame fm;
  10.         private ImageIcon ii_s;
  11.         private ImageIcon ii[]=new ImageIcon[54];
  12.         private JLabel lb;
  13.         private JButton btn;
  14.         private int x=(int)(Math.random()*54);
  15.         A90()
  16.         {
  17.                 ii_s=new ImageIcon(A90.class.getResource("pic/poker_icon.png"));
  18.                 for(int i=0;i<54;i++)
  19.                         ii[i]=new ImageIcon(A90.class.getResource("pic/poker"+(i+1)+".png"));
  20.                
  21.         lb=new JLabel(ii[x]);
  22.         lb.setBounds(80, 10, 234,351);
  23.         
  24.         btn=new JButton("下一張");
  25.         btn.setBounds(350, 310, 100, 30);
  26.         btn.addActionListener(this);
  27.         
  28.        
  29.                   fm=new JFrame("隨機撲克牌");
  30.                   fm.setIconImage(ii_s.getImage());
  31.                 fm.setBounds(100, 100, 500, 400);
  32.                 fm.setVisible(true);
  33.                 fm.setResizable(false);
  34.                 fm.setLayout(null);
  35.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  36.                 fm.add(btn);
  37.                 fm.add(lb);
  38.                
  39.         }
  40.         public void actionPerformed(ActionEvent e)
  41.         {
  42.                 if(e.getSource()==btn)
  43.                 {
  44.                         x=(int)(Math.random()*54);
  45.                         lb.setIcon(ii[x]);
  46.                 }
  47.         }
  48.    
  49.         public static void main(String[] args) {
  50.                  new A90();

  51.         }

  52. }
複製代碼

TOP

返回列表