| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2179 人关注过本帖, 1 人收藏
标题:用java画圆圈的程式问题
取消只看楼主 加入收藏
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
结帖率:41.67%
收藏(1)
 问题点数:0 回复次数:2 
用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 圆圈 程式 
2008-10-16 13:22
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
收藏
得分:0 
请具体回答一下, 不太懂什么叫找API最好, 或者说那3个程式要怎样才能运行, 我单独运行每一个程式, 没有一个行的, 现在是一头雾水, 高手请帮忙
2008-10-17 01:46
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
收藏
得分:0 
画五角星怎么办?? 能给个完整的程式吗?? 我是新手, 单说搞不明白
2008-10-17 11:36
快速回复:用java画圆圈的程式问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029134 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved