📄 sudokuboard_simplegui.java
字号:
// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov Date: 2/13/2008 10:17:47 PM
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: SudokuBoard_SimpleGUI.java
import java.awt.*;
import java.io.PrintStream;
import javax.swing.JFrame;
import javax.swing.JPanel;
class SudokuBoard_SimpleGUI extends JPanel
implements SudokuBoard
{
public SudokuBoard_SimpleGUI(SudokuGame sudokugame)
{
this(sudokugame, 500, 500, DEFAULT_GRID_COLOR, 0.20000000000000001D, "Sudoku");
}
public SudokuBoard_SimpleGUI(SudokuGame sudokugame, int i, int j, Color color, double d, String s)
{
game = sudokugame;
borderWidth = d;
gridColor = color;
xHeader = -1D;
yHeader = -1D;
xIncrement = -1D;
yIncrement = -1D;
initFrame(i, j, s);
}
protected void initFrame(int i, int j, String s)
{
frame = new JFrame(s);
frame.setSize(i, j);
frame.setContentPane(this);
frame.setVisible(true);
}
public void close()
{
frame.setVisible(false);
frame.dispose();
frame = null;
}
public void refresh()
{
repaint();
}
protected void resetMeasures()
{
yIncrement = ((double)getHeight() * (1.0D - borderWidth)) / (double)game.getSize();
xIncrement = ((double)getWidth() * (1.0D - borderWidth)) / (double)game.getSize();
yHeader = ((double)getHeight() * borderWidth) / 2D;
xHeader = ((double)getWidth() * borderWidth) / 2D;
}
public Point getTextLocation(int i, int j)
{
if(i < -1 || i > game.getSize() || j < -1 || j > game.getSize())
{
System.err.println((new StringBuilder()).append("PROGRAMMER ERROR! Somehow invalid values (").append(i).append(", ").append(j).append(") got passed to ").append("getTextLocation()").toString());
System.exit(0);
}
double d = i;
double d1 = j;
if(i < 0)
d = -0.75D;
if(j < 0)
d1 = -0.75D;
int k = (int)(xHeader + (d + 0.45000000000000001D) * xIncrement);
int l = (int)(yHeader + (d1 + 0.59999999999999998D) * yIncrement);
return new Point(k, l);
}
public void fillSquares(Graphics g)
{
for(int i = -1; i < game.getSize(); i++)
{
for(int j = -1; j < game.getSize(); j++)
{
Point point = getTextLocation(i, j);
int k;
if(i < 0)
k = j + 1;
else
if(j < 0)
k = i + 1;
else
k = game.getMatrix().get(j, i);
String s = (new StringBuilder()).append(k).append("").toString();
if(i < 0)
s = (new StringBuilder()).append((char)((65 + k) - 1)).append("").toString();
Color color = Color.black;
if(k == 0)
s = "";
else
if(k < 0)
{
s = (new StringBuilder()).append(-k).append("").toString();
color = Color.red;
}
g.setColor(color);
g.drawString(s, point.x, point.y);
}
}
}
void drawBoard(Graphics g)
{
double d = yHeader;
double d1 = xHeader;
int i = (int)yHeader;
int j = getHeight() - i;
int k = (int)xHeader;
int l = getWidth() - k;
int i1 = (int)((double)getWidth() * (1.0D - borderWidth));
int j1 = (int)((double)getHeight() * (1.0D - borderWidth));
g.setColor(gridColor);
for(int k1 = 0; k1 < game.getSize() + 1; k1++)
{
byte byte0 = 1;
if(k1 % game.getSectionSize() == 0)
byte0 = 3;
g.fillRect(k, (int)d, i1, byte0);
g.fillRect((int)d1, i, byte0, j1);
d += yIncrement;
d1 += xIncrement;
}
}
public void paintComponent(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
resetMeasures();
drawBoard(g);
fillSquares(g);
}
static final double DEFAULT_BORDER_WIDTH = 0.20000000000000001D;
static final double LABEL_FACTOR = -0.75D;
static final Color DEFAULT_GRID_COLOR;
static final int DEFAULT_FRAME_WIDTH = 500;
static final int DEFAULT_FRAME_HEIGHT = 500;
static final String DEFAULT_TITLE = "Sudoku";
SudokuGame game;
double borderWidth;
Color gridColor;
JFrame frame;
double xHeader;
double yHeader;
double xIncrement;
double yIncrement;
static
{
DEFAULT_GRID_COLOR = Color.BLACK;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -