Affichage des articles dont le libellé est How To Draw Chess Board In Java Swing Using NetBeans. Afficher tous les articles
Affichage des articles dont le libellé est How To Draw Chess Board In Java Swing Using NetBeans. Afficher tous les articles

Java - How To Draw Chess Board In Java Swing Using NetBeans

Java - How To Draw Chess Board In Java

In this java Tutorial we will see How To Draw Chess Board In Java NetBeans .



Project Source Code:

package javadb_001;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Work extends JPanel{
    
    public void paint(Graphics g){
        
        g.fillRect(100, 100, 400, 400);
        for(int i = 100; i <= 400; i+=100){
            for(int j = 100; j <= 400; j+=100){
                g.clearRect(i, j, 50, 50);
            }
        }
        
        for(int i = 150; i <= 450; i+=100){
            for(int j = 150; j <= 450; j+=100){
                g.clearRect(i, j, 50, 50);
            }
        }
    }
    public static void main(String[] args){
        JFrame frame = new JFrame();
        frame.setSize(600,600);
        frame.getContentPane().add(new Work());
        frame.setLocationRelativeTo(null);
        frame.setBackground(Color.LIGHT_GRAY);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }  
}
OUTPUT:
Chess Board In Java