本帖最後由 劉得恩 於 2016-4-23 17:39 編輯
- import javax.swing.*;
- import java.awt.event.*;
- public class Ch92 implements ActionListener
- {
- private JFrame f=new JFrame("23123");
- private JButton next=new JButton("下一個");
- private ImageIcon ii[]=new ImageIcon[54],ic;
- private JLabel l;
- int r[]=new int[54];
-
- Ch92()
- {
- f.setVisible(true);
- f.setResizable(false);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setLayout(null);
- ic=new ImageIcon(Ch92.class.getResource("pic/poker0.png" ));
- f.setBounds(100,100,500,400);
- f.setIconImage(ic.getImage());
- for(int i=0;i<54;i++)
- {
- ii[i]=new ImageIcon(Ch92.class.getResource("pic/poker"+(i+1)+".png" ));
- }
-
- l=new JLabel( ii[ (int)(Math.random()*54) ] );
- l.setBounds(80, 10, 234,351);
- f.add(l);
- next.setBounds(350, 310, 100, 30);
- next.addActionListener(this);
- f.add(next);
- }
- public static void main(String[] args)
- {
- new Ch92();
- }
- public void actionPerformed(ActionEvent e)
- {
-
- l.setIcon(ii[(int)(Math.random()*54)]);
- }
- }
複製代碼 |