I need to make a checkers board that has to be also resizeable. At the moment I'm using JPanel and it's method paintComponent to paint the squares. But the problem is with the class test: the squares drawn have to be squares and they cant go out of proportion, so I thought that maybe the solution would be to allow window resizing but so that it would keep its' shape as well (width and heigth would be equal) but I dont know how to solve it. Can somebody help me?
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import javax.swing.JPanel;
public class Tahvel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
Double ellipse = new Rectangle2D.Double(0,0,getWidth()/10,getHeight()/10);
g2.draw(ellipse);
g2.setColor(new Color(25,25,112));
g2.fill(ellipse);
}
}
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame {
Test(){
setTitle("XXXX");
getContentPane().add(new Tahvel());
}
public static void main(String args[]){
Test raam = new Test();
raam.setSize(500,500);
raam.setVisible(true);
}
}