n*****n 发帖数: 100 | 1 定义Graphics g
g.drawLine(X1,Y1,X2,Y2)
怎么能对这根直线加粗?在网上找了很久,找到的是用g.setStroke().
但是我加进这个之后,显示错误:the method setStroke is undefined for this
type of graphics. 我在这个中class都
import javax.swing.*;
import java.applet.Applet;
import java.awt.Graphics;
谢谢指教! |
m******y 发帖数: 102 | 2 用Graphics2D
【在 n*****n 的大作中提到】 : 定义Graphics g : g.drawLine(X1,Y1,X2,Y2) : 怎么能对这根直线加粗?在网上找了很久,找到的是用g.setStroke(). : 但是我加进这个之后,显示错误:the method setStroke is undefined for this : type of graphics. 我在这个中class都 : import javax.swing.*; : import java.applet.Applet; : import java.awt.Graphics; : 谢谢指教!
|
n*****g 发帖数: 7 | 3 well, use fillRect method to draw any width, haha~~~ |
w******p 发帖数: 166 | 4 public void paint (Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(6.0f);
g2.drawLine(...)
} |
n*****n 发帖数: 100 | 5 Many thinks to all concerned! |
g*****g 发帖数: 34805 | 6 this is the right way, fillRect probably wouldn't
enable anti-aliasing
【在 w******p 的大作中提到】 : public void paint (Graphics g) { : Graphics2D g2 = (Graphics2D) g; : g2.setStroke(new BasicStroke(6.0f); : g2.drawLine(...) : }
|
j******o 发帖数: 82 | 7 It depends. the performance of filling a polygon is better than that of
Java2D with a line stroke > 1. If it's just a horizontal or vertical line
you can use the polygon approach with simple math, although it is not
hard for a line with any slope either.
g.drawPolygon() will respect the antialiasing hint.
【在 g*****g 的大作中提到】 : this is the right way, fillRect probably wouldn't : enable anti-aliasing
|