Sat, 26 Jan 2013 17:42:07 +0100
check functions
universe@1 | 1 | package de.uapcore.sudoku; |
universe@1 | 2 | |
universe@1 | 3 | import java.awt.Color; |
universe@1 | 4 | import java.awt.Graphics; |
universe@1 | 5 | import java.awt.Graphics2D; |
universe@1 | 6 | import java.awt.GridBagConstraints; |
universe@1 | 7 | import java.awt.GridBagLayout; |
universe@1 | 8 | import java.awt.Insets; |
universe@1 | 9 | import java.awt.image.BufferedImage; |
universe@1 | 10 | import javax.swing.JPanel; |
universe@1 | 11 | |
universe@1 | 12 | /** |
universe@1 | 13 | * |
universe@1 | 14 | * @author mike |
universe@1 | 15 | */ |
universe@2 | 16 | public final class Field extends JPanel { |
universe@1 | 17 | private SudokuTextField[][] cells; |
universe@1 | 18 | |
universe@1 | 19 | public Field() { |
universe@1 | 20 | setBackground(Color.WHITE); |
universe@1 | 21 | |
universe@1 | 22 | setLayout(new GridBagLayout()); |
universe@1 | 23 | GridBagConstraints c = new GridBagConstraints(); |
universe@1 | 24 | c.insets = new Insets(5, 5, 5, 5); |
universe@1 | 25 | |
universe@1 | 26 | cells = new SudokuTextField[9][9]; |
universe@1 | 27 | for (int x = 0 ; x < 9 ; x++) { |
universe@1 | 28 | for (int y = 0 ; y < 9 ; y++) { |
universe@1 | 29 | cells[x][y] = new SudokuTextField(); |
universe@1 | 30 | c.gridx = x; |
universe@1 | 31 | c.gridy = y; |
universe@1 | 32 | add(cells[x][y], c); |
universe@1 | 33 | } |
universe@1 | 34 | } |
universe@1 | 35 | } |
universe@1 | 36 | |
universe@1 | 37 | @Override |
universe@1 | 38 | public void paint(Graphics graphics) { |
universe@1 | 39 | super.paint(graphics); |
universe@1 | 40 | final int w = getWidth(); |
universe@1 | 41 | final int h = getHeight(); |
universe@1 | 42 | final int cw = w / 9; |
universe@1 | 43 | final int ch = h / 9; |
universe@1 | 44 | |
universe@1 | 45 | BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
universe@1 | 46 | Graphics2D g = img.createGraphics(); |
universe@1 | 47 | g.setBackground(Color.WHITE); |
universe@1 | 48 | g.clearRect(0, 0, w, h); |
universe@1 | 49 | |
universe@1 | 50 | g.setColor(Color.BLACK); |
universe@1 | 51 | g.drawRect(1, 1, w-2, h-2); |
universe@1 | 52 | g.drawRect(2, 2, w-4, h-4); |
universe@1 | 53 | for (int x = cw ; x < w ; x += cw) { |
universe@1 | 54 | for (int y = ch ; y < h ; y += ch) { |
universe@1 | 55 | g.drawLine(x, 2, x, h-2); |
universe@1 | 56 | g.drawLine(2, y, w-2, y); |
universe@1 | 57 | if ((x / cw) % 3 == 0) { |
universe@1 | 58 | g.drawLine(x+1, 2, x+1, h-2); |
universe@1 | 59 | } |
universe@1 | 60 | if ((y / ch) % 3 == 0) { |
universe@1 | 61 | g.drawLine(2, y+1, w-2, y+1); |
universe@1 | 62 | } |
universe@1 | 63 | } |
universe@1 | 64 | } |
universe@1 | 65 | |
universe@1 | 66 | graphics.drawImage(img, 0, 0, this); |
universe@1 | 67 | } |
universe@1 | 68 | |
universe@2 | 69 | public int getCellValue(int x, int y) { |
universe@2 | 70 | return cells[x][y].getValue(); |
universe@2 | 71 | } |
universe@1 | 72 | |
universe@2 | 73 | public void setCellValue(int x, int y, int v) { |
universe@2 | 74 | cells[x][y].setValue(v); |
universe@2 | 75 | } |
universe@2 | 76 | |
universe@2 | 77 | public void setAllCellsModified(boolean modified) { |
universe@2 | 78 | for (int x = 0 ; x < 9 ; x++) { |
universe@2 | 79 | for (int y = 0 ; y < 9 ; y++) { |
universe@2 | 80 | cells[x][y].setModified(modified); |
universe@2 | 81 | } |
universe@2 | 82 | } |
universe@2 | 83 | } |
universe@2 | 84 | |
universe@2 | 85 | public boolean isAnyCellModified() { |
universe@2 | 86 | for (int x = 0 ; x < 9 ; x++) { |
universe@2 | 87 | for (int y = 0 ; y < 9 ; y++) { |
universe@2 | 88 | if (cells[x][y].isModified()) { |
universe@2 | 89 | return true; |
universe@2 | 90 | } |
universe@2 | 91 | } |
universe@2 | 92 | } |
universe@2 | 93 | return false; |
universe@2 | 94 | } |
universe@1 | 95 | } |