diff -r 93d6c51154a7 -r f1d7de36b01e src/de/uapcore/sudoku/Field.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/de/uapcore/sudoku/Field.java Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,70 @@ +package de.uapcore.sudoku; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.image.BufferedImage; +import javax.swing.JPanel; + +/** + * + * @author mike + */ +public class Field extends JPanel { + private SudokuTextField[][] cells; + + public Field() { + setBackground(Color.WHITE); + + setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + + cells = new SudokuTextField[9][9]; + for (int x = 0 ; x < 9 ; x++) { + for (int y = 0 ; y < 9 ; y++) { + cells[x][y] = new SudokuTextField(); + c.gridx = x; + c.gridy = y; + add(cells[x][y], c); + } + } + } + + @Override + public void paint(Graphics graphics) { + super.paint(graphics); + final int w = getWidth(); + final int h = getHeight(); + final int cw = w / 9; + final int ch = h / 9; + + BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + Graphics2D g = img.createGraphics(); + g.setBackground(Color.WHITE); + g.clearRect(0, 0, w, h); + + g.setColor(Color.BLACK); + g.drawRect(1, 1, w-2, h-2); + g.drawRect(2, 2, w-4, h-4); + for (int x = cw ; x < w ; x += cw) { + for (int y = ch ; y < h ; y += ch) { + g.drawLine(x, 2, x, h-2); + g.drawLine(2, y, w-2, y); + if ((x / cw) % 3 == 0) { + g.drawLine(x+1, 2, x+1, h-2); + } + if ((y / ch) % 3 == 0) { + g.drawLine(2, y+1, w-2, y+1); + } + } + } + + graphics.drawImage(img, 0, 0, this); + } + + +}