本帖最後由 陳泓瑜 於 2018-4-21 10:52 編輯
- public class RANDOM
- {
- public static void main(String[] args)
- {
-
- int j[]=new int[12];
- for(int i=0;i<12;i++)
- {
- j[i]=(int)(Math.random()*12);
- for(int k=0; k<i; k++)
- {
- if(j[i]==j[k])
- {
- i--;
- break;
- }
- }
-
- }
-
-
-
- for(int m=0; m<=11; m++)
- {
- System.out.println(j[m]);
- }
- }
- }
複製代碼- 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 FLIP extends JFrame {
- private JPanel contentPane;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- FLIP frame = new FLIP();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public FLIP() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 572, 466);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
-
- JLabel C1 = new JLabel("");
- C1.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C1.setBounds(10, 10, 128, 128);
- contentPane.add(C1);
-
- JLabel C2 = new JLabel("");
- C2.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C2.setBounds(148, 10, 128, 128);
- contentPane.add(C2);
-
- JLabel C3 = new JLabel("");
- C3.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C3.setBounds(286, 10, 128, 128);
- contentPane.add(C3);
-
- JLabel C4 = new JLabel("");
- C4.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C4.setBounds(424, 10, 128, 128);
- contentPane.add(C4);
- //----------------------
- JLabel C5 = new JLabel("");
- C5.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C5.setBounds(10, 148, 128, 128);
- contentPane.add(C5);
-
- JLabel C6 = new JLabel("");
- C6.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C6.setBounds(148, 148, 128, 128);
- contentPane.add(C6);
-
- JLabel C7 = new JLabel("");
- C7.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C7.setBounds(286, 148, 128, 128);
- contentPane.add(C7);
-
- JLabel C8 = new JLabel("");
- C8.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C8.setBounds(424, 148, 128, 128);
- contentPane.add(C8);
- //----------------------
- JLabel C9 = new JLabel("");
- C9.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C9.setBounds(10, 286, 128, 128);
- contentPane.add(C9);
-
- JLabel C10 = new JLabel("");
- C10.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C10.setBounds(148, 286, 128, 128);
- contentPane.add(C10);
-
- JLabel C11 = new JLabel("");
- C11.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C11.setBounds(286, 286, 128, 128);
- contentPane.add(C11);
-
- JLabel C12 = new JLabel("");
- C12.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
- C12.setBounds(424, 286, 128, 128);
- contentPane.add(C12);
- }
- }
複製代碼 |