返回列表 發帖
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3. import java.awt.Image;

  4. import javax.swing.ImageIcon;
  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.border.EmptyBorder;
  8. import javax.swing.JLabel;

  9. public class Main extends JFrame {

  10.         private JPanel contentPane;
  11.     public JLabel lb[] = new JLabel[12];
  12.     public ImageIcon[] card = new ImageIcon[12];
  13.        
  14.         public static void main(String[] args) {
  15.                 EventQueue.invokeLater(new Runnable() {
  16.                         public void run() {
  17.                                 try {
  18.                                         Main frame = new Main();
  19.                                         frame.setVisible(true);
  20.                                         frame.setTitle("翻牌遊戲");
  21.                                         ImageIcon icon = new ImageIcon(Main.class.getResource("star.png"));
  22.                                     Image image = icon.getImage();
  23.                                         frame.setIconImage(image);
  24.                                 } catch (Exception e) {
  25.                                         e.printStackTrace();
  26.                                 }
  27.                         }
  28.                 });
  29.         }

  30.    
  31.         public Main() {
  32.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.                 setBounds(100, 100, 589, 518);
  34.                 contentPane = new JPanel();
  35.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  36.                 setContentPane(contentPane);
  37.                 contentPane.setLayout(null);
  38.                
  39.                 JLabel lb1 = new JLabel("lb1");
  40.                 lb1.setBounds(10, 20, 128, 128);
  41.                 contentPane.add(lb1);
  42.                 //lb1.setIcon(entericon(0));
  43.                 lb[0] = lb1;
  44.                
  45.                 JLabel lb2 = new JLabel("lb2");
  46.                 lb2.setBounds(148, 20, 128, 128);
  47.                 contentPane.add(lb2);
  48.                 //lb2.setIcon(entericon(0));
  49.                 lb[1] = lb2;
  50.                
  51.                 JLabel lb3 = new JLabel("lb3");
  52.                 lb3.setBounds(288, 20, 128, 128);
  53.                 contentPane.add(lb3);
  54.                 //lb3.setIcon(entericon(0));
  55.                 lb[2] = lb3;
  56.                
  57.                 JLabel lb4 = new JLabel("lb4");
  58.                 lb4.setBounds(426, 20, 128, 128);
  59.                 contentPane.add(lb4);
  60.                 //lb4.setIcon(entericon(0));
  61.                 lb[3] = lb4;               
  62.                
  63.                 JLabel lb5 = new JLabel("lb5");
  64.                 lb5.setBounds(10, 155, 128, 128);
  65.                 contentPane.add(lb5);
  66.                 //lb5.setIcon(entericon(0));
  67.                 lb[4] = lb5;
  68.                
  69.                 JLabel lb6 = new JLabel("lb6");
  70.                 lb6.setBounds(148, 155, 128, 128);
  71.                 contentPane.add(lb6);
  72.                 //lb6.setIcon(entericon(0));
  73.                 lb[5] = lb6;
  74.                
  75.                 JLabel lb7 = new JLabel("lb7");
  76.                 lb7.setBounds(288, 155, 128, 128);
  77.                 contentPane.add(lb7);
  78.                 //lb7.setIcon(entericon(0));
  79.                 lb[6] = lb7;
  80.                
  81.                 JLabel lb8 = new JLabel("lb8");
  82.                 lb8.setBounds(426, 155, 128, 128);
  83.                 contentPane.add(lb8);
  84.                 //lb8.setIcon(entericon(0));
  85.                 lb[7] = lb8;
  86.                
  87.                 JLabel lb9 = new JLabel("lb9");
  88.                 lb9.setBounds(10, 293, 128, 128);
  89.                 contentPane.add(lb9);
  90.                 //lb9.setIcon(entericon(0));
  91.                 lb[8] = lb9;
  92.                
  93.                 JLabel lb10 = new JLabel("lb10");
  94.                 lb10.setBounds(148, 293, 128, 128);
  95.                 contentPane.add(lb10);
  96.                 //lb10.setIcon(entericon(0));
  97.                 lb[9] = lb10;
  98.        
  99.                 JLabel lb11 = new JLabel("lb11");
  100.                 lb11.setBounds(288, 293, 128, 128);
  101.                 contentPane.add(lb11);
  102.                 //lb11.setIcon(entericon(0));
  103.                 lb[10] = lb11;
  104.                
  105.                 JLabel lb12 = new JLabel("lb12");
  106.                 lb12.setBounds(426, 293, 128, 128);
  107.                 contentPane.add(lb12);
  108.                 //lb12.setIcon(entericon(0));
  109.                 lb[11] = lb12;
  110.                
  111.                 JLabel lb13 = new JLabel("lb13");
  112.                 lb13.setBounds(521, 431, 33, 33);
  113.                 contentPane.add(lb13);
  114.                 lb13.setIcon(entericon(7));
  115.                
  116.                 entericon_2(lb);               
  117.         }
  118.         public ImageIcon entericon(int n)  
  119.         {
  120.                 ImageIcon icon = new ImageIcon(Main.class.getResource(n+".png"));
  121.             return icon;
  122.         }
  123.         public void entericon_2(JLabel[] lb)
  124.         {
  125.                 for(int i=0; i<lb.length; i++)
  126.                 {
  127.                         ImageIcon icon = new ImageIcon(Main.class.getResource(String.format("%d.%s", 0,"png")));
  128.                         lb[i].setIcon(icon);
  129.                         lb[i].setSize(128, 128);
  130.                 }
  131.         }
  132.         public void randomcard(ImageIcon card[])
  133.         {
  134.                 ImageIcon icon = new ImageIcon(Main.class.getResource(String.format("%d.%s", Math.random()*12,"png")));
  135.                 Image image = icon.getImage().getScaledInstance(128, 128, java.awt.Image.SCALE_FAST);
  136.                 ImageIcon newicon = new ImageIcon(image);
  137.                 for(int i=0; i<card.length; i++)
  138.                 {
  139.                        
  140.                 }
  141.         }
  142. }
複製代碼

TOP

返回列表