返回列表 發帖
  1. package ch90;

  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;
  4. import javax.swing.JButton;
  5. import javax.swing.ImageIcon;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.ActionEvent;
  8. public class Ch90 implements ActionListener{
  9.          private JFrame fm;
  10.          private JLabel lb;
  11.          private JButton btn1;
  12.          private ImageIcon icon1;
  13.          private ImageIcon icon_s;
  14.          
  15.          Ch90()
  16.          {
  17.                  icon_s=new ImageIcon(Ch90.class.getResource("pic/poker_icon.png"));
  18.                   
  19.                           icon1=new ImageIcon(Ch90.class.getResource("pic/poker"+(int)(Math.random()*52+1)+".png"));
  20.                  

  21.                  lb.setBounds(80, 10, 234,351);
  22.                  
  23.                  btn1=new JButton("下一張");
  24.                  btn1.setBounds(350, 310, 100, 30);
  25.                  btn1.addActionListener(this);
  26.                  btn1.setVisible(true);

  27.                  
  28.                  fm=new JFrame("任抽一張撲克牌");
  29.                  fm.setBounds(100, 100, 500, 400);
  30.                  fm.setVisible(true);
  31.                  fm.setResizable(false);
  32.                  fm.setLayout(null);
  33.                  fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.                  fm.add(lb);
  35.                  fm.add(btn1);      
  36.          }
  37.          
  38.           public void actionPerformed(ActionEvent e)
  39.           {
  40.                   if(e.getSource()==btn1)
  41.                   icon1=new ImageIcon(Ch90.class.getResource("pic/poker"+(int)(Math.random()*52+1)+".png"));
  42.                   lb.setIcon(icon1);
  43.           }         
  44.          
  45.          public static void main(String[] args) {
  46.                    Ch90 app=new Ch90();
  47.          }
  48. }
複製代碼

TOP

返回列表