- package ch90;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import javax.swing.ImageIcon;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Ch90 implements ActionListener{
- private JFrame fm;
- private JLabel lb;
- private JButton btn1;
- private ImageIcon icon1;
- private ImageIcon icon_s;
-
- Ch90()
- {
- icon_s=new ImageIcon(Ch90.class.getResource("pic/poker_icon.png"));
-
- icon1=new ImageIcon(Ch90.class.getResource("pic/poker"+(int)(Math.random()*52+1)+".png"));
-
- lb.setBounds(80, 10, 234,351);
-
- btn1=new JButton("下一張");
- btn1.setBounds(350, 310, 100, 30);
- btn1.addActionListener(this);
- btn1.setVisible(true);
-
- fm=new JFrame("任抽一張撲克牌");
- fm.setBounds(100, 100, 500, 400);
- fm.setVisible(true);
- fm.setResizable(false);
- fm.setLayout(null);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.add(lb);
- fm.add(btn1);
- }
-
- public void actionPerformed(ActionEvent e)
- {
- if(e.getSource()==btn1)
- icon1=new ImageIcon(Ch90.class.getResource("pic/poker"+(int)(Math.random()*52+1)+".png"));
- lb.setIcon(icon1);
- }
-
- public static void main(String[] args) {
- Ch90 app=new Ch90();
- }
- }
複製代碼 |