返回列表 發帖
本帖最後由 劉得恩 於 2016-4-23 17:39 編輯
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. public class Ch92 implements ActionListener
  4. {

  5.         private JFrame f=new JFrame("23123");
  6.         private JButton next=new JButton("下一個");
  7.         private ImageIcon ii[]=new ImageIcon[54],ic;
  8.         private JLabel l;
  9.         int r[]=new int[54];
  10.        
  11.         Ch92()
  12.         {
  13.                 f.setVisible(true);
  14.                 f.setResizable(false);
  15.                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.                 f.setLayout(null);
  17.                 ic=new ImageIcon(Ch92.class.getResource("pic/poker0.png" ));
  18.                 f.setBounds(100,100,500,400);
  19.                 f.setIconImage(ic.getImage());
  20.                 for(int i=0;i<54;i++)
  21.                 {
  22.                         ii[i]=new ImageIcon(Ch92.class.getResource("pic/poker"+(i+1)+".png" ));
  23.                 }
  24.                
  25.                 l=new JLabel( ii[ (int)(Math.random()*54) ] );
  26.                 l.setBounds(80, 10, 234,351);
  27.                 f.add(l);
  28.                 next.setBounds(350, 310, 100, 30);
  29.                 next.addActionListener(this);
  30.                 f.add(next);
  31.         }
  32.         public static void main(String[] args)
  33.         {
  34.                 new Ch92();
  35.         }
  36.         public void actionPerformed(ActionEvent e)
  37.         {
  38.                
  39.                 l.setIcon(ii[(int)(Math.random()*54)]);
  40.         }
  41. }
複製代碼

TOP

返回列表