Bonjour,

j'essaie de tester les fonctions graphiques, cependant je n'arrive pas à utiliser correctement l'antiliasing et autres paramètres. Le segment que j'affiche est bon lorsque la fenêtre est petite mais dès que j'écris ou que je change la taille ce ne donne pas des traits vraiment droits ...! je comprends pas

J'ai fait une boulette dans mon code ? :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
63
64
65
66
import java.awt.*;
 
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.applet.*;
 
public class Cmain
extends Applet {
int xd, yd, x, y;
public void init() { addMouseListener(new Appuyeur());
addMouseMotionListener(new Dragueur()); }
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
	//Object[] stored = (Object[]) restoreData(context);
/*	super.paint(g);
	BufferedImage image = new BufferedImage(1600, 1600, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2 = image.createGraphics();
*/
Graphics2D g2= (Graphics2D) g;
 
//g2.setTransform()
g2.setStroke(new BasicStroke(3.f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_ROUND, 1.f));
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
        RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
		   RenderingHints.VALUE_STROKE_NORMALIZE);
g2.setRenderingHint(RenderingHints.KEY_DITHERING,
		   RenderingHints.VALUE_DITHER_ENABLE);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
		   RenderingHints.VALUE_INTERPOLATION_BICUBIC);
//g2.setRenderingHint(RenderingHints.KEY_RENDERING,
	//	   RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2.drawLine(10, 10, 200, 300);
 
g2.drawLine((int)(xd),(int)(yd),(int)(x),(int)(y));
 
xd = x; yd = y;
 
}
class Appuyeur extends MouseAdapter {
public void mousePressed(MouseEvent e) {
xd = e.getX(); yd = e.getY();
 
}
}
class Dragueur extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
x = e.getX(); y = e.getY();
 
repaint();
}
}
public void repaint()
{
// repaint le component courant
super.repaint();
// repaint tous les components qu'il possède
for(int i = 0; i < this.getComponentCount(); i++)
this.getComponent(i).repaint();
} 
}