- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class A90 implements ActionListener
- {
- private JFrame fm;
- private ImageIcon ii_s;
- private ImageIcon ii[]=new ImageIcon[54];
- private JLabel lb;
- private JButton btn;
- private int x=(int)(Math.random()*54);
- A90()
- {
- ii_s=new ImageIcon(A90.class.getResource("pic/poker_icon.png"));
- for(int i=0;i<54;i++)
- ii[i]=new ImageIcon(A90.class.getResource("pic/poker"+(i+1)+".png"));
-
- lb=new JLabel(ii[x]);
- lb.setBounds(80, 10, 234,351);
-
- btn=new JButton("下一張");
- btn.setBounds(350, 310, 100, 30);
- btn.addActionListener(this);
-
-
- fm=new JFrame("隨機撲克牌");
- fm.setIconImage(ii_s.getImage());
- fm.setBounds(100, 100, 500, 400);
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setLayout(null);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.add(btn);
- fm.add(lb);
-
- }
- public void actionPerformed(ActionEvent e)
- {
- if(e.getSource()==btn)
- {
- x=(int)(Math.random()*54);
- lb.setIcon(ii[x]);
- }
- }
-
- public static void main(String[] args) {
- new A90();
- }
- }
複製代碼 |