56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| import javax.swing.*;
 | |
| import java.awt.*;
 | |
| 
 | |
| class Affiche extends JComponent {
 | |
| 
 | |
|     @Override
 | |
|     protected void paintComponent(Graphics g) {
 | |
|         super.paintComponent(g);
 | |
| 
 | |
|         if (isOpaque()) {
 | |
|             g.setColor(getBackground());
 | |
|             g.fillRect(0, 0, getWidth(), getHeight());
 | |
|         }
 | |
| 
 | |
|         Graphics2D pinceau = (Graphics2D) g.create();
 | |
| 
 | |
|         int pionTaille = 50;
 | |
|         int pas = 70;
 | |
|         int yBase = 60;
 | |
|         int tabJeu[][] = {{0,0,1,2,0,0,0,0,0},
 | |
|                           {0,1,2,1,2,0,0,0,0},
 | |
|                           {0,2,1,2,1,2,1,0,0},
 | |
|                           {0,1,2,1,2,1,2,1,2},
 | |
|                           {1,2,1,2,0,2,1,2,1},
 | |
|                           {2,1,2,1,2,1,2,1,0},
 | |
|                           {0,0,1,2,1,2,1,2,0},
 | |
|                           {0,0,0,0,2,1,2,1,0},
 | |
|                           {0,0,0,0,0,2,1,0,0}};
 | |
| 
 | |
|         for (int i = 0; i < pionsParLigne.length; i++) {
 | |
|             int nbPions = pionsParLigne[i];
 | |
|             int x = 60 + decalageLigne[i];
 | |
|             int y = yBase + i * pas;
 | |
| 
 | |
|             for (int j = 0; j < nbPions; j++) {
 | |
|                 if ((i+j) % 2 == 0)
 | |
|                     pinceau.setColor(Color.BLUE);
 | |
|                 else
 | |
|                     pinceau.setColor(Color.RED);
 | |
| 
 | |
|                 pinceau.fillOval(x + j * pas, y, pionTaille, pionTaille);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         pinceau.dispose();
 | |
|     }
 | |
| 
 | |
|     public static void main(String[] args) {
 | |
|         JFrame fenetre = new JFrame("Forme diagonale miroir");
 | |
|         fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 | |
|         fenetre.setSize(900, 800);
 | |
|         fenetre.add(new Affiche());
 | |
|         fenetre.setVisible(true);
 | |
|     }
 | |
| }
 |