1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/de/uapcore/sudoku/Field.java Sat Jan 26 15:48:59 2013 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +package de.uapcore.sudoku; 1.5 + 1.6 +import java.awt.Color; 1.7 +import java.awt.Graphics; 1.8 +import java.awt.Graphics2D; 1.9 +import java.awt.GridBagConstraints; 1.10 +import java.awt.GridBagLayout; 1.11 +import java.awt.Insets; 1.12 +import java.awt.image.BufferedImage; 1.13 +import javax.swing.JPanel; 1.14 + 1.15 +/** 1.16 + * 1.17 + * @author mike 1.18 + */ 1.19 +public class Field extends JPanel { 1.20 + private SudokuTextField[][] cells; 1.21 + 1.22 + public Field() { 1.23 + setBackground(Color.WHITE); 1.24 + 1.25 + setLayout(new GridBagLayout()); 1.26 + GridBagConstraints c = new GridBagConstraints(); 1.27 + c.insets = new Insets(5, 5, 5, 5); 1.28 + 1.29 + cells = new SudokuTextField[9][9]; 1.30 + for (int x = 0 ; x < 9 ; x++) { 1.31 + for (int y = 0 ; y < 9 ; y++) { 1.32 + cells[x][y] = new SudokuTextField(); 1.33 + c.gridx = x; 1.34 + c.gridy = y; 1.35 + add(cells[x][y], c); 1.36 + } 1.37 + } 1.38 + } 1.39 + 1.40 + @Override 1.41 + public void paint(Graphics graphics) { 1.42 + super.paint(graphics); 1.43 + final int w = getWidth(); 1.44 + final int h = getHeight(); 1.45 + final int cw = w / 9; 1.46 + final int ch = h / 9; 1.47 + 1.48 + BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 1.49 + Graphics2D g = img.createGraphics(); 1.50 + g.setBackground(Color.WHITE); 1.51 + g.clearRect(0, 0, w, h); 1.52 + 1.53 + g.setColor(Color.BLACK); 1.54 + g.drawRect(1, 1, w-2, h-2); 1.55 + g.drawRect(2, 2, w-4, h-4); 1.56 + for (int x = cw ; x < w ; x += cw) { 1.57 + for (int y = ch ; y < h ; y += ch) { 1.58 + g.drawLine(x, 2, x, h-2); 1.59 + g.drawLine(2, y, w-2, y); 1.60 + if ((x / cw) % 3 == 0) { 1.61 + g.drawLine(x+1, 2, x+1, h-2); 1.62 + } 1.63 + if ((y / ch) % 3 == 0) { 1.64 + g.drawLine(2, y+1, w-2, y+1); 1.65 + } 1.66 + } 1.67 + } 1.68 + 1.69 + graphics.drawImage(img, 0, 0, this); 1.70 + } 1.71 + 1.72 + 1.73 +}