1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
   |  
public class Test {
 
	public static void main(String args[]) throws Exception {
 
		Jeu jeu = new Jeu();
 
 
 
	}
}
 
class Jeu extends JFrame 
{
 
	public Jeu()
	{
		super("Exemple de jeu");
		this.getContentPane().add(new BouleContainer(2,2));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.pack();
		this.setVisible(true);
	}
 
}
 
class Boule extends JPanel
{
 
	public Boule()
	{
 
	}
 
	public Dimension getPreferredSize()
	{
		return new Dimension(110,110);
	}
	public void paintComponent(Graphics g)
	{
		g.setColor(Color.RED);
		g.drawRect(0,0,100,100);
		g.drawOval(10,10,10,10);
	}
}
 
class BouleContainer extends JPanel
{
	private int w;
	private int h;
 
	public BouleContainer(int w, int h)
	{
		this.w = w;
		this.h = h;
 
		this.setLayout(new GridLayout(this.w, this.h));
		for(int i = 0;i < w * h;i++)
			this.add(new Boule());
	}
 
} | 
Partager