0

I designed chess board game before , i did for loop for rows and i did for loop for column ... and the result appear good . But here i want to make the board by two inner loop inside them .
I do that but the rows not appear
please any one help me .
My code:
-----------

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;

public class MovePawnTest extends JFrame {

    private BoardGame board;

    public MovePawnTest() {
        board = new BoardGame();
        getContentPane().add(board, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
        MovePawnTest movePawnTest = new MovePawnTest();
        movePawnTest.setDefaultCloseOperation(MovePawnTest.EXIT_ON_CLOSE);
        movePawnTest.setSize(new Dimension(600, 300));
        movePawnTest.setLocationRelativeTo(null);
        movePawnTest.setVisible(true);
        movePawnTest.setExtendedState(MAXIMIZED_BOTH);

    }
}
import java.awt.Graphics;
import javax.swing.JPanel;

public class BoardGame extends JPanel {

    private final int ROW = 8, COL = 8, x = 100, y = 60;
    private int[][] board;

    public BoardGame() {
        board = new int[ROW][COL];
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        drawBoard(g);
    }

    private void drawBoard(Graphics g) {
        for (int i = 0; i < ROW; ++i) {
            for (int j = 0; j < COL; ++j) {
                g.drawLine((x * j) + 100, (y * i) + 60, (x * j) + 100, y * 8);
            }
        }
    }
}

Thnaks in advance

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by beshoyatef
0

Because you told your program to draw only vertical lines and did not told it to draw horizontal. Configure this correctly and you get also horizontal lines

g.drawLine((x * j) + 100, (y * i) + 60, (x * j) + 100, y * 8);
g.drawLine(100, (y * i) + 60, 1000,(y * i) + 60);
0

Because you told your program to draw only vertical lines and did not told it to draw horizontal. Configure this correctly and you get also horizontal lines

g.drawLine((x * j) + 100, (y * i) + 60, (x * j) + 100, y * 8);
g.drawLine(100, (y * i) + 60, 1000,(y * i) + 60);

Thanks for reply ..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.