0
JButtonの二つのディスプレイでは、2つのクラス私のJButtonが一貫して表示されていない、助けてくださいそれは同じ大きさではなく、2つの場所やサイズが同じ場所
がありませんそれはサイズと位置 と一致していませんおかげ コードは、2つのセクション
最終パブリッククラスChessMain {
JFrame frame;
public static void main(String[] args) {
new ChessMain().go();
}
private void go() {
frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Container contentPane = frame.getContentPane();
frame.setContentPane(new DrawPanelChess());
frame.setVisible(true);
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
Icon warnIcon = new ImageIcon("white_King_Chess.png");
JButton button2 = new JButton(warnIcon);
button2.setLayout(null);
button2.setBounds(100,0, 100, 100);
frame.add(button2);
}
}
にダウン以下であります10クラスDrawPanelChessはJPanelの{
private static final long serialVersionUID = 9166938856558245300L;
ます。public void paintComponent(グラフィックスグラム){
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Color.WHITE);
{//row 1
g.fillRect(0, 0, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/4, 0, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/2, 0, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 6, 0, this.getWidth()/8, this.getHeight()/8);
}
{//row 2
g.fillRect(this.getWidth()/8, this.getHeight()/8, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 3, this.getHeight()/8, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 5, this.getHeight()/8, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 7, this.getHeight()/8, this.getWidth()/8, this.getHeight()/8);
}
{//row 3
g.fillRect(0, this.getHeight()/4, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/4, this.getHeight()/4, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/2, this.getHeight()/4, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 6, this.getHeight()/4, this.getWidth()/8, this.getHeight()/8);
}
{//row 4
g.fillRect(this.getWidth()/8, this.getHeight()/8 * 3, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 3, this.getHeight()/8 * 3, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 5, this.getHeight()/8 * 3, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 7, this.getHeight()/8 * 3, this.getWidth()/8, this.getHeight()/8);
}
{//row 5
g.fillRect(0, this.getHeight()/2, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/4, this.getHeight()/2, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/2, this.getHeight()/2, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 6, this.getHeight()/2, this.getWidth()/8, this.getHeight()/8);
}
{//row 6
g.fillRect(this.getWidth()/8, this.getHeight()/8 * 5, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 3, this.getHeight()/8 * 5, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 5, this.getHeight()/8 * 5, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 7, this.getHeight()/8 * 5, this.getWidth()/8, this.getHeight()/8);
}
{//row 7
g.fillRect(0, this.getHeight()/8 * 6, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/4, this.getHeight()/8 * 6, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/2, this.getHeight()/8 * 6, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 6, this.getHeight()/8 * 6, this.getWidth()/8, this.getHeight()/8);
}
{//row 8
g.fillRect(this.getWidth()/8, this.getHeight()/8 * 7, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 3, this.getHeight()/8 * 7, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 5, this.getHeight()/8 * 7, this.getWidth()/8, this.getHeight()/8);
g.fillRect(this.getWidth()/8 * 7, this.getHeight()/8 * 7, this.getWidth()/8, this.getHeight()/8);
}
// System.out.println("\u2654");
repaint();
} }あなたがあなたのDrawPanelChessを追加した後のフレームにボタンを追加するようだ