九路盤を印刷したかったので、ざっくりと作成。
九路盤を印刷したかったので、ざっくりと作成。 KyurobanFrame.java
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
@SuppressWarnings("serial")
public class KyurobanFrame extends JPanel {
final protected List<GoLine> fLineList = new ArrayList<GoLine>();
final protected static int SIZE_X = 890;
final protected static int SIZE_Y = 980;
final public static int BASE_X = 25;
final public static int BASE_Y = 25;
final public static int RATE_X = 105;
// 横に対して、0.05ほど縦が長い。
final public static int RATE_Y = 111;
public KyurobanFrame() {
// 背景色を白色にします
setBackground(Color.white);
for (int index = 0; index < 9; index++) {
// ここに書き足していく。
// たての線
fLineList.add(new GoLine(index, 0, index, 8));
}
for (int index = 0; index < 9; index++) {
// ここに書き足していく。
// よこの線
fLineList.add(new GoLine(0, index, 8, index));
}
try {
final BufferedImage bufImg = new BufferedImage(SIZE_X, SIZE_Y,
BufferedImage.TYPE_INT_RGB);
final Graphics graph = bufImg.getGraphics();
graph.setColor(Color.white);
graph.fillRect(0, 0, SIZE_X, SIZE_Y);
paintComponent(graph);
graph.dispose();
new File("tmp").mkdirs();
ImageIO.write(bufImg, "png", new File("./tmp/Kyuroban.png"));
} catch (IOException e) {
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}
public void paintComponent(final Graphics argGraphics) {
super.paintComponent(argGraphics);
for (final GoLine look : fLineList) {
look.draw(argGraphics);
}
// 星
argGraphics.fillOval(BASE_X + RATE_X * 4 - 5, BASE_Y + RATE_Y * 4 - 5,
12, 12);
argGraphics.fillOval(BASE_X + RATE_X * 2 - 5, BASE_Y + RATE_Y * 2 - 5,
12, 12);
argGraphics.fillOval(BASE_X + RATE_X * 6 - 5, BASE_Y + RATE_Y * 2 - 5,
12, 12);
argGraphics.fillOval(BASE_X + RATE_X * 2 - 5, BASE_Y + RATE_Y * 6 - 5,
12, 12);
argGraphics.fillOval(BASE_X + RATE_X * 6 - 5, BASE_Y + RATE_Y * 6 - 5,
12, 12);
}
private static void createAndShowGUI() {
final JFrame frame = new JFrame("九路盤フレーム");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new KyurobanFrame());
frame.setLocationRelativeTo(null);
frame.setSize(SIZE_X, SIZE_Y);
frame.setVisible(true);
}
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
GoLine.java
import java.awt.Color;
import java.awt.Graphics;
public class GoLine {
protected int fX1;
protected int fY1;
protected int fX2;
protected int fY2;
protected Color fColor = Color.black;
public GoLine(final int x1, final int y1, final int x2, final int y2) {
fX1 = x1;
fY1 = y1;
fX2 = x2;
fY2 = y2;
}
public void setColor(final Color color) {
fColor = color;
}
public void draw(final Graphics argGraphics) {
argGraphics.setColor(fColor);
argGraphics.drawLine(KyurobanFrame.BASE_X + fX1 * KyurobanFrame.RATE_X,
KyurobanFrame.BASE_Y + fY1 * KyurobanFrame.RATE_Y,
KyurobanFrame.BASE_X + (fX2) * KyurobanFrame.RATE_X,
KyurobanFrame.BASE_Y + (fY2) * KyurobanFrame.RATE_Y);
argGraphics.drawLine(1 + KyurobanFrame.BASE_X + fX1
* KyurobanFrame.RATE_X, 1 + KyurobanFrame.BASE_Y + fY1
* KyurobanFrame.RATE_Y, 1 + KyurobanFrame.BASE_X + (fX2)
* KyurobanFrame.RATE_X, 1 + KyurobanFrame.BASE_Y + (fY2)
* KyurobanFrame.RATE_Y);
}
}