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
| public class PanneauFlashcode extends JPanel {
private int nombreCarre=19;
private int[][] flashcode = new int[nombreCarre][nombreCarre];
private JPanel panel;
public PanneauFlashcode(int [][] carre,JPanel panel)
{
this.panel = panel;
for(int y =0;y<nombreCarre; y++)
{
for(int x = 0 ; x<nombreCarre;x++)
{
carre[x][y]=flashcode[x][y];
}
}
paintComponent(panel.getGraphics());
}
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.WHITE);
g2.drawRect(0, 0, 570, 570);
g2.setColor(Color.BLACK);
for(int y = 0; y<nombreCarre;y++ )
{
for(int x = 0 ; x<nombreCarre ; x++ )
{
if(flashcode[x][y]==1)
g2.drawRect(x*30, y*30, (x+1)*30, (y+1)*30);
}
}
BufferedImage monBuffer = g2.getDeviceConfiguration().createCompatibleImage(570, 570);
try{
ImageIO.write(monBuffer, "jpg", new File("monBuffer.jpg"));
}catch(Exception ex) {ex.printStackTrace();}
g2.dispose();
}
} |
Partager