Ejemplo n.º 1
0
  public D(String title) {
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 410;
    int frameHeight = 319;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    setResizable(false);
    Container cp = getContentPane();
    cp.setLayout(null);

    label1.setBounds(8, 8, 275, 76);
    label1.setText("Würfel");
    label1.setAlignment(Label.CENTER);
    label1.setFont(new Font("Dialog", Font.PLAIN, 60));
    cp.add(label1);
    l_1.setBounds(8, 88, 275, 145);
    l_1.setText("");
    l_1.setAlignment(Label.CENTER);
    l_1.setFont(new Font("Dialog", Font.PLAIN, 100));

    cp.add(l_1);
    b_1.setBounds(8, 248, 275, 25);
    b_1.setLabel("Würfeln");
    b_1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            b_1_ActionPerformed(evt);
          }
        });
    cp.add(b_1);
    tf_von.setBounds(336, 80, 49, 25);
    cp.add(tf_von);
    tf_bis.setBounds(336, 120, 49, 25);
    cp.add(tf_bis);
    l_von.setBounds(296, 80, 35, 25);
    l_von.setText("Von:");
    cp.add(l_von);
    l_bis.setBounds(296, 120, 35, 25);
    l_bis.setText("Bis:");
    cp.add(l_bis);
    b_a.setBounds(296, 160, 89, 49);
    b_a.setLabel("Annehmen");
    b_a.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            b_a_ActionPerformed(evt);
          }
        });
    cp.add(b_a);

    setVisible(true);
  }
Ejemplo n.º 2
0
  // swing gui / constructor
  public Main(final Field f) {
    super("Sudoku Solver");
    URL iconURL = getClass().getResource("icon.png");
    ImageIcon img = new ImageIcon(iconURL);
    jFrame.setIconImage(img.getImage());
    Color darkBlue = new Color(51, 102, 153);
    Color lightBlue = new Color(18, 61, 104);

    grid = new JTextField[9][9];
    jGrid.setLayout(new GridLayout(9, 9));
    jGrid.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, darkBlue));
    jGrid.setBackground(darkBlue);
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        grid[i][j] = new JTextField();
        grid[i][j].setDocument(new JTextFieldLimit(1));
        grid[i][j].setFont(new Font("Arial", Font.PLAIN, 20));
        grid[i][j].setHorizontalAlignment(JTextField.CENTER);
        grid[i][j].setText("");
        grid[i][j].setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, lightBlue));
        if (j == 2 || j == 5) {
          grid[i][j].setBorder(BorderFactory.createMatteBorder(1, 1, 1, 5, lightBlue));
        }
        if (i == 2 || i == 5) {
          grid[i][j].setBorder(BorderFactory.createMatteBorder(1, 1, 5, 1, lightBlue));
        }
        if (i == 2 && j == 2) {
          grid[i][j].setBorder(BorderFactory.createMatteBorder(1, 1, 5, 5, lightBlue));
        }
        if (i == 5 && j == 2) {
          grid[i][j].setBorder(BorderFactory.createMatteBorder(1, 1, 5, 5, lightBlue));
        }
        if (i == 2 && j == 5) {
          grid[i][j].setBorder(BorderFactory.createMatteBorder(1, 1, 5, 5, lightBlue));
        }
        if (i == 5 && j == 5) {
          grid[i][j].setBorder(BorderFactory.createMatteBorder(1, 1, 5, 5, lightBlue));
        }
        jGrid.add(grid[i][j]);
      }
    }

    jButton.setLayout(new FlowLayout());
    jButton.setBackground(darkBlue);
    jButton.setPreferredSize(new Dimension(420, 45));

    jButton.add(solve);
    solve.setLabel("Solve");
    solve.setVisible(true);
    solve.setFont(new Font("HelveticaNeue", Font.PLAIN, 20));
    solve.setForeground(Color.BLACK);

    jButton.add(upload);
    upload.setLabel("Upload");
    upload.setVisible(true);
    upload.setFont(new Font("Arial", Font.PLAIN, 20));
    upload.setForeground(Color.BLACK);

    jButton.add(clear);
    clear.setLabel("Clear");
    clear.setVisible(true);
    clear.setFont(new Font("Arial", Font.PLAIN, 20));
    clear.setForeground(Color.BLACK);

    jGrid.setPreferredSize(new Dimension(400, 400));

    jFrame.setResizable(false);
    jFrame.setVisible(true);
    jFrame.setLocationRelativeTo(null);
    jFrame.setSize(420, 480);
    jFrame.setBackground(darkBlue);

    jFrame.add(jGrid, BorderLayout.PAGE_START);
    jFrame.add(jButton, BorderLayout.PAGE_END);

    ActionListener solvedClicked =
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            makeGridWhite();
            gridToModel(f);
            if (!errorFound(f)) {
              runSolve(f);
              makeGrid(f, false);
              solve.setEnabled(false);
            }
          }
        };

    ActionListener uploadClicked =
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            makeGridWhite();
            f.clearModel();
            makeGrid(f, true);
            solve.setEnabled(true);
            f.fromFile();
            makeGrid(f, true);
          }
        };

    ActionListener clearClicked =
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            makeGridWhite();
            f.clearModel();
            makeGrid(f, true);
            solve.setEnabled(true);
          }
        };

    solve.addActionListener(solvedClicked);
    upload.addActionListener(uploadClicked);
    clear.addActionListener(clearClicked);
  }