import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class RoundedButton extends JButton {
public RoundedButton() { super(); decorate(); }
public RoundedButton(String text) { super(text); decorate(); }
public RoundedButton(Action action) { super(action); decorate(); }
public RoundedButton(Icon icon) { super(icon); decorate(); }
public RoundedButton(String text, Icon icon) { super(text, icon); decorate(); }
protected void decorate() { setBorderPainted(false); setOpaque(false); }
@Override
protected void paintComponent(Graphics g) {
Color c=new Color(255,247,242); //배경색 결정
Color o=new Color(247,99,12); //글자색 결정
int width = getWidth();
int height = getHeight();
Graphics2D graphics = (Graphics2D) g;
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (getModel().isArmed()) { graphics.setColor(c.darker()); }
else if (getModel().isRollover()) { graphics.setColor(c.brighter()); }
else { graphics.setColor(c); }
graphics.fillRoundRect(0, 0, width, height, 10, 10);
FontMetrics fontMetrics = graphics.getFontMetrics();
Rectangle stringBounds = fontMetrics.getStringBounds(this.getText(), graphics).getBounds();
int textX = (width - stringBounds.width) / 2;
int textY = (height - stringBounds.height) / 2 + fontMetrics.getAscent();
graphics.setColor(o);
graphics.setFont(getFont());
graphics.drawString(getText(), textX, textY);
graphics.dispose();
super.paintComponent(g);
}
}
public class Main extends JFrame {
int MapSize[] = new int[2];
Container cnt = getContentPane();
JButton [][] ChePiece;
Vector<String, String, String> ChePiece = Vector<String, String, String>();
public Main() {
MapSize[0] = 8;
MapSize[1] = 8;
ChePiece = new JButton[MapSize[0]][MapSize[0]];
setTitle("Main Chess Game");
setSize(715, 715);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
cnt.setLayout(null);
for(int i = 0; i < MapSize[1]; i++) {
for(int j = 0; j < MapSize[0]; j++) {
ChePiece[i][j] = new JButton(/*new ImageIcon("C:\\Users\\SooahCodeLab\\Desktop\\RgChessImage\\bishop.png")*/);
if(j == 1 || j == 6)
ChePiece[i][j].setIcon(new ImageIcon("C:\\Users\\SooahCodeLab\\Desktop\\RgChessImage\\pawn.png"));
else if(j == 0 || j == 7) {
if(i == 0 || i == 7)
ChePiece[i][j].setIcon(new ImageIcon("C:\\Users\\SooahCodeLab\\Desktop\\RgChessImage\\rook.png"));
else if(i == 1 || i == 6)
ChePiece[i][j].setIcon(new ImageIcon("C:\\Users\\SooahCodeLab\\Desktop\\RgChessImage\\horse.png"));
else if(i == 2 || i ==5)
ChePiece[i][j].setIcon(new ImageIcon("C:\\Users\\SooahCodeLab\\Desktop\\RgChessImage\\bishop.png"));
}
ChePiece[i][j].setContentAreaFilled(false);
ChePiece[i][j].setSize(45,45);
ChePiece[i][j].setLocation((715 - 55*MapSize[0])/2 + i*55 , (715 - 55*MapSize[1])/2 + j*55);
cnt.add(ChePiece[i][j]);
}
}
repaint();
revalidate();
}
public static void main(String[] args) {
new Main();
}
}



