Je veux dessiner des rectangles dans différents temps, quand je dessine le premier rectangle par paint(), j'utilise paint() pour dessiner un second puis un premier rectangle disparaît. J'ai trouvé qu'une image remplaçait une image précédente. Comment puis-je faire sans recréer les précédents (comme ne pas utiliser repaint())? J'apprécie chaque réponse: dcomment faire 2d graphique en Java sans repeindre()?
public static class Screen extends Frame
{
int WIDTH = 900;
static int[][] map = new int[700][700];
public Screen()
{
super("Clash of Tank");
setSize(WIDTH, WIDTH);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void paint(Graphics g) {
BufferedImage image = (BufferedImage) createImage(700,700);
Graphics g2 = image.getGraphics();
drawTank(g2);
g.drawImage(image, 325, 35, this);
}
void drawTank(Graphics g) {
g.setColor(Color.BLACK);
for(int i = 0; i<=690; i+=1)
for(int j = 0; j<=690; j+=1)
{
if(map[i][j]==0)
g.setColor(Color.BLACK);
if((map[i][j]==1))
g.setColor(Color.BLUE);
if((map[i][j]==2))
g.setColor(Color.RED);
if((map[i][j]==3))
g.setColor(Color.GREEN);
if((map[i][j]==4))
g.setColor(Color.YELLOW);
g.fillRect(i, j, 1, 1);
}
}
}
public class ClashofTanks
{
public static void main(String[] args) throws Exception
{
Screen t = new Screen();
t.setVisible(true);
t.repaint();
}
}
......... Bonjour? –