本帖最後由 李允軒 於 2016-4-23 18:02 編輯
- 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 Ch01 implements ActionListener {
- private JButton bt1;
- private JFrame fm;
- private JLabel lb;
- private ImageIcon icon_s;
- private ImageIcon icon,icon1;
-
- Ch01(){
- bt1=new JButton("下一張");
- bt1.addActionListener(this);
- bt1.setBounds(350, 310, 100, 30);
- bt1.setVisible(true);
-
- icon_s=new ImageIcon(Ch01.class.getResource("pic/poker_icon.png"));
-
- icon=new ImageIcon(Ch01.class.getResource("pic/poker"+(int)(Math.random()*53+1)+".png"));
-
-
- lb=new JLabel(icon);
- lb.setBounds(80, 10, 234,351);
-
- fm=new JFrame("poker");
- fm.setIconImage(icon_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(lb);
- fm.add(bt1);
- }
-
- public void actionPerformed(ActionEvent e){
- if(e.getSource()==bt1){
- icon1=new ImageIcon(Ch01.class.getResource("pic/poker"+(int)(Math.random()*53+1)+".png"));
- lb.setIcon(icon1);
- }
- }
- public static void main(String[] args) {
- Ch01 app=new Ch01();
- }
- }
複製代碼 |