- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.awt.Image;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- public class Main extends JFrame {
- private JPanel contentPane;
- public JLabel lb[] = new JLabel[12];
- public ImageIcon[] card = new ImageIcon[12];
-
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Main frame = new Main();
- frame.setVisible(true);
- frame.setTitle("翻牌遊戲");
- ImageIcon icon = new ImageIcon(Main.class.getResource("star.png"));
- Image image = icon.getImage();
- frame.setIconImage(image);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- public Main() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 589, 518);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
-
- JLabel lb1 = new JLabel("lb1");
- lb1.setBounds(10, 20, 128, 128);
- contentPane.add(lb1);
- //lb1.setIcon(entericon(0));
- lb[0] = lb1;
-
- JLabel lb2 = new JLabel("lb2");
- lb2.setBounds(148, 20, 128, 128);
- contentPane.add(lb2);
- //lb2.setIcon(entericon(0));
- lb[1] = lb2;
-
- JLabel lb3 = new JLabel("lb3");
- lb3.setBounds(288, 20, 128, 128);
- contentPane.add(lb3);
- //lb3.setIcon(entericon(0));
- lb[2] = lb3;
-
- JLabel lb4 = new JLabel("lb4");
- lb4.setBounds(426, 20, 128, 128);
- contentPane.add(lb4);
- //lb4.setIcon(entericon(0));
- lb[3] = lb4;
-
- JLabel lb5 = new JLabel("lb5");
- lb5.setBounds(10, 155, 128, 128);
- contentPane.add(lb5);
- //lb5.setIcon(entericon(0));
- lb[4] = lb5;
-
- JLabel lb6 = new JLabel("lb6");
- lb6.setBounds(148, 155, 128, 128);
- contentPane.add(lb6);
- //lb6.setIcon(entericon(0));
- lb[5] = lb6;
-
- JLabel lb7 = new JLabel("lb7");
- lb7.setBounds(288, 155, 128, 128);
- contentPane.add(lb7);
- //lb7.setIcon(entericon(0));
- lb[6] = lb7;
-
- JLabel lb8 = new JLabel("lb8");
- lb8.setBounds(426, 155, 128, 128);
- contentPane.add(lb8);
- //lb8.setIcon(entericon(0));
- lb[7] = lb8;
-
- JLabel lb9 = new JLabel("lb9");
- lb9.setBounds(10, 293, 128, 128);
- contentPane.add(lb9);
- //lb9.setIcon(entericon(0));
- lb[8] = lb9;
-
- JLabel lb10 = new JLabel("lb10");
- lb10.setBounds(148, 293, 128, 128);
- contentPane.add(lb10);
- //lb10.setIcon(entericon(0));
- lb[9] = lb10;
-
- JLabel lb11 = new JLabel("lb11");
- lb11.setBounds(288, 293, 128, 128);
- contentPane.add(lb11);
- //lb11.setIcon(entericon(0));
- lb[10] = lb11;
-
- JLabel lb12 = new JLabel("lb12");
- lb12.setBounds(426, 293, 128, 128);
- contentPane.add(lb12);
- //lb12.setIcon(entericon(0));
- lb[11] = lb12;
-
- JLabel lb13 = new JLabel("lb13");
- lb13.setBounds(521, 431, 33, 33);
- contentPane.add(lb13);
- lb13.setIcon(entericon(7));
-
- entericon_2(lb);
- }
- public ImageIcon entericon(int n)
- {
- ImageIcon icon = new ImageIcon(Main.class.getResource(n+".png"));
- return icon;
- }
- public void entericon_2(JLabel[] lb)
- {
- for(int i=0; i<lb.length; i++)
- {
- ImageIcon icon = new ImageIcon(Main.class.getResource(String.format("%d.%s", 0,"png")));
- lb[i].setIcon(icon);
- lb[i].setSize(128, 128);
- }
- }
- public void randomcard(ImageIcon card[])
- {
- ImageIcon icon = new ImageIcon(Main.class.getResource(String.format("%d.%s", Math.random()*12,"png")));
- Image image = icon.getImage().getScaledInstance(128, 128, java.awt.Image.SCALE_FAST);
- ImageIcon newicon = new ImageIcon(image);
- for(int i=0; i<card.length; i++)
- {
-
- }
- }
- }
複製代碼 |