Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionclass Paint_Dessin extends JPanel { private static final long serialVersionUID = -2110723486099015303L; // pour la position au pif de la ligne private static final Random RAND = new Random(); private BufferedImage buffer = null; @Override public void paintComponent(final Graphics g) { // super.paintComponent(g); // pas besoin // setBackground(Color.white); // pas besoin // g.setColor(Color.black); // pas besoin final Graphics2D g2 = (Graphics2D) g; g2.clearRect(0, 0, getWidth(), getHeight()); // cleanup du composant g2.drawImage(getBuffer(), null, 0, 0); } public void TracerLigne() { // System.out.println("LIGNE"); // pas besoin final Graphics2D g2 = getBuffer().createGraphics(); // juste pour lisser la ligne g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // couleur de la ligne g2.setColor(Color.BLACK); // dessin la ligne au pif dans l'espace visible final int x1 = RAND.nextInt(500); // position en X1 final int y1 = RAND.nextInt(500); // position en Y1 final int x2 = RAND.nextInt(500); // position en X2 final int y2 = RAND.nextInt(500); // position en Y2 g2.drawLine(x1, y1, x2, y2); Line2D.Double line = new Line2D.Double(x1, y1, x2, y2); g2.fill(line); repaint();// force le repaint de l'objet } // petit plus public void TracerOval() { final Graphics2D g2 = getBuffer().createGraphics(); // juste pour lisser la ligne g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // couleur du cercle g2.setColor(Color.RED); //ajout d'une transparence aléatoire g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, RAND.nextFloat())); // dessin la ligne au pif dans l'espace visible final int x = RAND.nextInt(500); // position en X final int y = RAND.nextInt(500); // position en Y final int w = RAND.nextInt(500); // Lageur final int h = RAND.nextInt(500); // Hauteur g2.fillOval(x, y, w, h); Ellipse2D.Double ellipse = new Ellipse2D.Double(x, y, w, h); g2.fill(ellipse); repaint();// force le repaint de l'objet } // petit plus public void clear() { final Graphics2D g2 = getBuffer().createGraphics(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f)); Rectangle2D.Double rect = new Rectangle2D.Double(0,0,getWidth(),getHeight()); g2.fill(rect); repaint(); } private BufferedImage getBuffer() { if (buffer == null) buffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); return buffer; } }