Java BasicStroke "Fuzzy"
I'm trying to write a simple paint applet with Java, but I'm having trouble with BasicStroke
. Initially, my plan was to try to somehow draw a line with a width, but the API apparently doesn't support that.
I tried using BasicStroke
, but the result is just a fuzzy mess. How can I fix开发者_Go百科 this fuzz problem?
private void mousedrag_hook(Point point)
{
if(start == null)
start = point;
end = point;
Graphics2D g2d = (Graphics2D)applInstance.buffer_g;
g2d.setStroke(new BasicStroke(7));
//g2d.fillOval(point.x - 5, point.y - 5, 10, 10);
g2d.drawLine(start.x, start.y, end.x, end.y);
applInstance.repaint();
start = end;
}
Don't forget the RenderingHints
:
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
...
}
精彩评论