java画圈,用java画圆圈的程式问题

ca56232b3bbedf9a539d07f37fffb99a.gif

3144d8b7615c79d9f638db40d5689d26.gif

a218af6549b45ee526caf607ebff1358.gif

0f8df0e29816ae721419de940fb833d1.gif

用java画圆圈的程式问题

这是我书上的程式,我想问下面的三个程式中, 哪一个才是画圈, 还是3个要一起用才能运行???如果三个要一起用,如何写成一个程式。 我刚接触java,一窍不通, 所以请高手指点

//*****************************************************************************

//  CirclePanel.java       Programming with Alice and Java

//

//  Represents the drawing panel in the DrawCircles program.

//*****************************************************************************

import java.awt.*;

import javax.swing.JPanel;

public class CirclePanel extends JPanel

{

private Circle circle1, circle2, circle3;

//--------------------------------------------------------------------------

//  Creates three Circle objects and sets panel characteristics.

//--------------------------------------------------------------------------

public CirclePanel()

{

circle1 = new Circle(150, 200, 100, Color.red);

circle2 = new Circle(200, 50, 35, Color.yellow);

circle3 = new Circle(285, 150, 60, Color.green);

setBackground(Color.black);

setPreferredSize(new Dimension(400, 350));

}

//--------------------------------------------------------------------------

//  Draws three circles on the panel.

//--------------------------------------------------------------------------

public void paintComponent(Graphics gc)

{

super.paintComponent(gc);

circle1.drawFilled(gc);

circle2.drawFilled(gc);

circle3.drawFilled(gc);

}

}

//*****************************************************************************

//  DrawCircles.java       Programming with Alice and Java

//

//  Demonstrates the use of a frame containing a panel on which shapes can

//  be drawn.

//*****************************************************************************

import javax.swing.JFrame;

public class DrawCircles

{

//--------------------------------------------------------------------------

//  Creates and displays the application frame, which contains the drawing

//  panel.

//--------------------------------------------------------------------------

public static void main(String[] args)

{

CirclePanel panel = new CirclePanel();

JFrame frame = new JFrame("Draw Circles");

frame.getContentPane().add(panel);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.pack();

frame.setVisible(true);

}

}

//*****************************************************************************

//  Circle.java       Programming with Alice and Java

//

//  Represents a circle with a particular size, color, and location. The

//  circle can be drawn filled or unfilled.

//*****************************************************************************

import java.awt.*;

public class Circle

{

private int radius;

private Color color;

private int x, y;  // the circle's center point

//--------------------------------------------------------------------------

//  Sets up the circle with the specified location, size, and color.

//--------------------------------------------------------------------------

public Circle(int xCenter, int yCenter, int size, Color circleColor)

{

x = xCenter;

y = yCenter;

radius = size;

color = circleColor;

}

//--------------------------------------------------------------------------

//  Draws the circle, filled, in the specified graphics context.

//--------------------------------------------------------------------------

public void drawFilled(Graphics gc)

{

gc.setColor(color);

gc.fillOval(x-radius, y-radius, radius*2, radius*2);

}

//--------------------------------------------------------------------------

//  Draws the circle, unfilled (outline only), in the specified graphics

//  context.

//--------------------------------------------------------------------------

public void drawUnfilled(Graphics gc)

{

gc.setColor(color);

gc.drawOval(x-radius, y-radius, radius*2, radius*2);

}

}

搜索更多相关主题的帖子:

java 圆圈 程式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值