Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.util.*;
- public class Panel extends JPanel {
- public int x0y0value = 0;
- public int x0y1value = 0;
- public int x0y2value = 0;
- public int x0y3value = 0;
- public int x0y4value = 0;
- public int x0y5value = 0;
- public int x0y6value = 0;
- public int x0y7value = 0;
- public int x0y8value = 0;
- public int x1y0value = 0;
- public int x1y1value = 0;
- public int x1y2value = 0;
- public int x1y3value = 0;
- public int x1y4value = 0;
- public int x1y5value = 0;
- public int x1y6value = 0;
- public int x1y7value = 0;
- public int x1y8value = 0;
- public int x2y0value = 0;
- public int x2y1value = 0;
- public int x2y2value = 0;
- public int x2y3value = 0;
- public int x2y4value = 0;
- public int x2y5value = 0;
- public int x2y6value = 0;
- public int x2y7value = 0;
- public int x2y8value = 0;
- public int x3y0value = 0;
- public int x3y1value = 0;
- public int x3y2value = 0;
- public int x3y3value = 0;
- public int x3y4value = 0;
- public int x3y5value = 0;
- public int x3y6value = 0;
- public int x3y7value = 0;
- public int x3y8value = 0;
- public int x4y0value = 0;
- public int x4y1value = 0;
- public int x4y2value = 0;
- public int x4y3value = 0;
- public int x4y4value = 0;
- public int x4y5value = 0;
- public int x4y6value = 0;
- public int x4y7value = 0;
- public int x4y8value = 0;
- public int x5y0value = 0;
- public int x5y1value = 0;
- public int x5y2value = 0;
- public int x5y3value = 0;
- public int x5y4value = 0;
- public int x5y5value = 0;
- public int x5y6value = 0;
- public int x5y7value = 0;
- public int x5y8value = 0;
- public int x6y0value = 0;
- public int x6y1value = 0;
- public int x6y2value = 0;
- public int x6y3value = 0;
- public int x6y4value = 0;
- public int x6y5value = 0;
- public int x6y6value = 0;
- public int x6y7value = 0;
- public int x6y8value = 0;
- public int x7y0value = 0;
- public int x7y1value = 0;
- public int x7y2value = 0;
- public int x7y3value = 0;
- public int x7y4value = 0;
- public int x7y5value = 0;
- public int x7y6value = 0;
- public int x7y7value = 0;
- public int x7y8value = 0;
- public int x8y0value = 0;
- public int x8y1value = 0;
- public int x8y2value = 0;
- public int x8y3value = 0;
- public int x8y4value = 0;
- public int x8y5value = 0;
- public int x8y6value = 0;
- public int x8y7value = 0;
- public int x8y8value = 0;
- public int countCount = 0;
- JTextField text1 = new JTextField();
- JTextField text2 = new JTextField();
- JTextField text3 = new JTextField();
- JTextField text4 = new JTextField();
- JTextField text5 = new JTextField();
- JTextField text6 = new JTextField();
- JTextField text7 = new JTextField();
- JTextField text8 = new JTextField();
- JTextField text9 = new JTextField();
- JTextField text10 = new JTextField();
- JTextField text11 = new JTextField();
- JTextField text12 = new JTextField();
- JTextField text13 = new JTextField();
- JTextField text14 = new JTextField();
- JTextField text15 = new JTextField();
- JTextField text16 = new JTextField();
- JTextField text17 = new JTextField();
- JTextField text18 = new JTextField();
- JTextField text19 = new JTextField();
- JTextField text20 = new JTextField();
- JTextField text21 = new JTextField();
- JTextField text22 = new JTextField();
- JTextField text23 = new JTextField();
- JTextField text24 = new JTextField();
- JTextField text25 = new JTextField();
- JTextField[] text = { text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15, text16,
- text17, text18, text19, text20, text21, text22, text23, text24, text25
- };
- JLabel x0y0label = new JLabel();
- JLabel x0y1label = new JLabel();
- JLabel x0y2label = new JLabel();
- JLabel x0y3label = new JLabel();
- JLabel x0y4label = new JLabel();
- JLabel x0y5label = new JLabel();
- JLabel x0y6label = new JLabel();
- JLabel x0y7label = new JLabel();
- JLabel x0y8label = new JLabel();
- JLabel x1y0label = new JLabel();
- JLabel x1y1label = new JLabel();
- JLabel x1y2label = new JLabel();
- JLabel x1y3label = new JLabel();
- JLabel x1y4label = new JLabel();
- JLabel x1y5label = new JLabel();
- JLabel x1y6label = new JLabel();
- JLabel x1y7label = new JLabel();
- JLabel x1y8label = new JLabel();
- JLabel x2y0label = new JLabel();
- JLabel x2y1label = new JLabel();
- JLabel x2y2label = new JLabel();
- JLabel x2y3label = new JLabel();
- JLabel x2y4label = new JLabel();
- JLabel x2y5label = new JLabel();
- JLabel x2y6label = new JLabel();
- JLabel x2y7label = new JLabel();
- JLabel x2y8label = new JLabel();
- JLabel x3y0label = new JLabel();
- JLabel x3y1label = new JLabel();
- JLabel x3y2label = new JLabel();
- JLabel x3y3label = new JLabel();
- JLabel x3y4label = new JLabel();
- JLabel x3y5label = new JLabel();
- JLabel x3y6label = new JLabel();
- JLabel x3y7label = new JLabel();
- JLabel x3y8label = new JLabel();
- JLabel x4y0label = new JLabel();
- JLabel x4y1label = new JLabel();
- JLabel x4y2label = new JLabel();
- JLabel x4y3label = new JLabel();
- JLabel x4y4label = new JLabel();
- JLabel x4y5label = new JLabel();
- JLabel x4y6label = new JLabel();
- JLabel x4y7label = new JLabel();
- JLabel x4y8label = new JLabel();
- JLabel x5y0label = new JLabel();
- JLabel x5y1label = new JLabel();
- JLabel x5y2label = new JLabel();
- JLabel x5y3label = new JLabel();
- JLabel x5y4label = new JLabel();
- JLabel x5y5label = new JLabel();
- JLabel x5y6label = new JLabel();
- JLabel x5y7label = new JLabel();
- JLabel x5y8label = new JLabel();
- JLabel x6y0label = new JLabel();
- JLabel x6y1label = new JLabel();
- JLabel x6y2label = new JLabel();
- JLabel x6y3label = new JLabel();
- JLabel x6y4label = new JLabel();
- JLabel x6y5label = new JLabel();
- JLabel x6y6label = new JLabel();
- JLabel x6y7label = new JLabel();
- JLabel x6y8label = new JLabel();
- JLabel x7y0label = new JLabel();
- JLabel x7y1label = new JLabel();
- JLabel x7y2label = new JLabel();
- JLabel x7y3label = new JLabel();
- JLabel x7y4label = new JLabel();
- JLabel x7y5label = new JLabel();
- JLabel x7y6label = new JLabel();
- JLabel x7y7label = new JLabel();
- JLabel x7y8label = new JLabel();
- JLabel x8y0label = new JLabel();
- JLabel x8y1label = new JLabel();
- JLabel x8y2label = new JLabel();
- JLabel x8y3label = new JLabel();
- JLabel x8y4label = new JLabel();
- JLabel x8y5label = new JLabel();
- JLabel x8y6label = new JLabel();
- JLabel x8y7label = new JLabel();
- JLabel x8y8label = new JLabel();
- JLabel[] x0label = { x0y0label, x0y1label, x0y2label, x0y3label, x0y4label, x0y5label, x0y6label, x0y7label, x0y8label };
- JLabel[] x1label = { x1y0label, x1y1label, x1y2label, x1y3label, x1y4label, x1y5label, x1y6label, x1y7label, x1y8label };
- JLabel[] x2label = { x2y0label, x2y1label, x2y2label, x2y3label, x2y4label, x2y5label, x2y6label, x2y7label, x2y8label };
- JLabel[] x3label = { x3y0label, x3y1label, x3y2label, x3y3label, x3y4label, x3y5label, x3y6label, x3y7label, x3y8label };
- JLabel[] x4label = { x4y0label, x4y1label, x4y2label, x4y3label, x4y4label, x4y5label, x4y6label, x4y7label, x4y8label };
- JLabel[] x5label = { x5y0label, x5y1label, x5y2label, x5y3label, x5y4label, x5y5label, x5y6label, x5y7label, x5y8label };
- JLabel[] x6label = { x6y0label, x6y1label, x6y2label, x6y3label, x6y4label, x6y5label, x6y6label, x6y7label, x6y8label };
- JLabel[] x7label = { x7y0label, x7y1label, x7y2label, x7y3label, x7y4label, x7y5label, x7y6label, x7y7label, x7y8label };
- JLabel[] x8label = { x8y0label, x8y1label, x8y2label, x8y3label, x8y4label, x8y5label, x8y6label, x8y7label, x8y8label };
- JLabel[][] label = { x0label, x1label, x2label, x3label, x4label, x5label, x6label, x7label, x8label };
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- int[] x0value = { x0y0value, x0y1value, x0y2value, x0y3value, x0y4value, x0y5value, x0y6value, x0y7value, x0y8value };
- int[] x1value = { x1y0value, x1y1value, x1y2value, x1y3value, x1y4value, x1y5value, x1y6value, x1y7value, x1y8value };
- int[] x2value = { x2y0value, x2y1value, x2y2value, x2y3value, x2y4value, x2y5value, x2y6value, x2y7value, x2y8value };
- int[] x3value = { x3y0value, x3y1value, x3y2value, x3y3value, x3y4value, x3y5value, x3y6value, x3y7value, x3y8value };
- int[] x4value = { x4y0value, x4y1value, x4y2value, x4y3value, x4y4value, x4y5value, x4y6value, x4y7value, x4y8value };
- int[] x5value = { x5y0value, x5y1value, x5y2value, x5y3value, x5y4value, x5y5value, x5y6value, x5y7value, x5y8value };
- int[] x6value = { x6y0value, x6y1value, x6y2value, x6y3value, x6y4value, x6y5value, x6y6value, x6y7value, x6y8value };
- int[] x7value = { x7y0value, x7y1value, x7y2value, x7y3value, x7y4value, x7y5value, x7y6value, x7y7value, x7y8value };
- int[] x8value = { x8y0value, x8y1value, x8y2value, x8y3value, x8y4value, x8y5value, x8y6value, x8y7value, x8y8value };
- int[][] xvalue = { x0value, x1value, x2value, x3value, x4value, x5value, x6value, x7value, x8value };
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- int[] y0value = { x0y0value, x1y0value, x2y0value, x3y0value, x4y0value, x5y0value, x6y0value, x7y0value, x8y0value };
- int[] y1value = { x0y1value, x1y1value, x2y1value, x3y1value, x4y1value, x5y1value, x6y1value, x7y1value, x8y1value };
- int[] y2value = { x0y2value, x1y2value, x2y2value, x3y2value, x4y2value, x5y2value, x6y2value, x7y2value, x8y2value };
- int[] y3value = { x0y3value, x1y3value, x2y3value, x3y3value, x4y3value, x5y3value, x6y3value, x7y3value, x8y3value };
- int[] y4value = { x0y4value, x1y4value, x2y4value, x3y4value, x4y4value, x5y4value, x6y4value, x7y4value, x8y4value };
- int[] y5value = { x0y5value, x1y5value, x2y5value, x3y5value, x4y5value, x5y5value, x6y5value, x7y5value, x8y5value };
- int[] y6value = { x0y6value, x1y6value, x2y6value, x3y6value, x4y6value, x5y6value, x6y6value, x7y6value, x8y6value };
- int[] y7value = { x0y7value, x1y7value, x2y7value, x3y7value, x4y7value, x5y7value, x6y7value, x7y7value, x8y7value };
- int[] y8value = { x0y8value, x1y8value, x2y8value, x3y8value, x4y8value, x5y8value, x6y8value, x7y8value, x8y8value };
- int[][] yvalue = { y0value, y1value, y2value, y3value, y4value, y5value, y6value, y7value, y8value };
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- int count1 = 0;
- int count2 = 0;
- int count3 = 0;
- int count4 = 0;
- int count5 = 0;
- int count6 = 0;
- int count7 = 0;
- int count8 = 0;
- int count9 = 0;
- int[] countArray = { 0, count1, count2, count3, count4, count5, count6, count7, count8, count9 };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Random random = new Random();
- public int numOfText = random.nextInt(24) + 8;
- public Panel() {
- if (numOfText >= 25) {
- numOfText = numOfText - 8;
- }
- System.out.println(numOfText);
- Dimension size = getPreferredSize();
- size.width = 500;
- size.height = 500;
- setPreferredSize(size);
- setLayout(new GridBagLayout());
- GridBagConstraints gc = new GridBagConstraints();
- for (int i = 0; i < 9; i++) {
- for (int i2 = 0; i2 < 9; i2++) {
- gc.anchor = GridBagConstraints.CENTER;
- gc.weightx = 0.15;
- gc.weighty = 0.15;
- gc.gridx = i;
- gc.gridy = i2;
- add(label[i][i2], gc);
- }
- }
- for (int i = 0; i < 9; i++) {
- for (int i2 = 0; i2 < 9; i2++) {
- label[i][i2].setText("" +xvalue[i][i2]);
- }
- }
- for (int i = 0; i <= numOfText;) {
- gc.anchor = GridBagConstraints.CENTER;
- gc.weightx = 0.15;
- gc.weighty = 0.15;
- int randomx = random.nextInt(8);
- int randomy = random.nextInt(8);
- gc.gridx = randomx;
- gc.gridy = randomy;
- if (xvalue[randomx][randomy] < 1) {
- // remove(label[randomx][randomy]);
- add(text[i], gc);
- text[i].setPreferredSize(new Dimension(25, 25));
- text[i].setHorizontalAlignment(JTextField.CENTER);
- text[i].setEditable(true);
- text[i].setVisible(true);
- text[i].setColumns(0);
- revalidate();
- repaint();
- xvalue[randomx][randomy]++;
- i++;
- }
- }
- boolean good1 = false;
- boolean good2 = false;
- boolean restart = true;
- for (int i = 0; i <= 8; i++) {
- for (int i2 = 0; i2 <= 8;) {
- int temp = random.nextInt(9) + 1;
- if (temp == 10) {
- temp = temp - 1;
- }
- int temp2 = 0;
- good1 = false;
- good2 = false;
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- for (int o = 0; o < countArray.length; o++) {
- countArray[o] = 0;
- }
- countArray[temp]++;
- for (int g = 0; g <= 8; g++) {
- temp2 = yvalue[i][g];
- countArray[temp2]++;
- }
- if (countArray[0] < 2 && countArray[1] < 2 && countArray[2] < 2 && countArray[3] < 2 && countArray[4] < 2 && countArray[5] < 2
- && countArray[6] < 2 && countArray[7] < 2 && countArray[8] < 2) {
- good1 = true;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- for (int o = 0; o < countArray.length; o++) {
- countArray[o] = 0;
- }
- countArray[temp]++;
- for (int g = 0; g <= 8; g++) {
- temp2 = xvalue[i][g];
- countArray[temp2]++;
- }
- if (countArray[0] < 2 && countArray[1] < 2 && countArray[2] < 2 && countArray[3] < 2 && countArray[4] < 2 && countArray[5] < 2
- && countArray[6] < 2 && countArray[7] < 2 && countArray[8] < 2) {
- good2 = true;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if (good1 == true && good2 == true) {
- xvalue[i][i2] = temp;
- yvalue[i2][i] = temp;
- i2++;
- }
- System.out.println(temp);
- }
- }
- for (int i = 0; i < 9; i++) {
- for (int i2 = 0; i2 < 9; i2++) {
- label[i][i2].setText("" +xvalue[i][i2]);
- }
- }
- setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement