当前位置: 代码迷 >> Java相关 >> 怎么样画圆用drawstring 参数不能为double
  详细解决方案

怎么样画圆用drawstring 参数不能为double

热度:420   发布时间:2007-03-17 20:31:09.0
怎么样画圆用drawstring 参数不能为double
怎么样画圆用drawstring 参数不能为double
用三角函数怎么画呢
搜索更多相关的解决方案: drawstring  double  参数  三角函数  

----------------解决方案--------------------------------------------------------
public class circlestar extends Applet{
public static float pi=3.1415926f;

public void paint(Graphics2D a)
{
float i=0;

for(i=0;i<=2*pi;i=i+0.1f)
{
float x=(float) Math.cos(i)*50+60;
float y=(float)Math.sin(i)*50+70;

a.drawString("★", x, y);


}

这个怎么画不出来呢
----------------解决方案--------------------------------------------------------
/**
* @(#)MyTest.java
*
*
* @author if
* @version 1.00 2007/3/17
*/

import java.awt.*;
import javax.swing.*;

public class MyTest extends JPanel{
public static float pi=3.1415926f;

public void paint(Graphics g){
float i=0;
Graphics2D g2=(Graphics2D)g;

for(i=0;i<=2*pi;i=i+0.1f){
float x=(float) Math.cos(i)*50+60;
float y=(float)Math.sin(i)*50+70;

g2.drawString("★", x, y);
}
}

public static void main(String[] args){
JFrame jFrame=new JFrame("paint test");
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.getContentPane().add(new MyTest());
jFrame.setSize(400,400);
jFrame.setVisible(true);
}
}
----------------解决方案--------------------------------------------------------
double型进行计算时改为Doubel
----------------解决方案--------------------------------------------------------
  相关解决方案