public void draw( Graphics g) {Graphics2D g2d = (G

发布时间:2021-02-26 08:11:37

public void draw( Graphics g) {Graphics2D g2d = (Graphics2D) g;final int x = getX();final int y = getY();g2d.setColor( Color.GREEN );g2d.setPaint( new GradientPaint( x,y,Color.GREEN,x + RADIUS/4,y + R

网友回答

public void draw( Graphics g) {
Graphics2D g2d = (Graphics2D) g;
//转化g的类型为Graphics2D final int x = getX()//;取得x坐标
final int y = getY();
//取得y坐标g2d.setColor( Color.GREEN );
//设置填充色greeng2d.setPaint( new GradientPaint( x, y, Color.GREEN, x + RADIUS/4, y + RADIUS/4, Color.BLACK, true) );//设置填充方式,从点x,y到点x + RADIUS/4, y + RADIUS/4的颜色渐变从green到black
int xOffset = 0;
//初始化x轴偏移变量int yOffset = 0;
//初始化y轴偏移变量for( int i = 0; i xOffset = (int) (Math.random()*RADIUS);
yOffset = (int) (Math.random()*RADIUS);
g2d.draw( new Ellipse2D.Double( x + xOffset, y + yOffset, x + xOffset+3, y + yOffset+3) );//画一个椭圆
}}
以上问题属网友观点,不代表本站立场,仅供参考!