【发布时间】:2009-07-13 23:52:52
【问题描述】:
我在编写 java 小程序并将其与 html 文件链接时遇到问题
java 小程序是关于绘制饼图 3 值销售、会员和添加。 java小程序的代码:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* Class AppDemo - write a description of the class here
*
* @author (your name)
* @version (a version number)
*/
public class AppDemo extends JApplet
{
public void init()
{
Container appC = getContentPane();
MyPanel myp = new MyPanel() ;
myp.setBorder(new EtchedBorder() ) ;
myp.setBackground(Color.red);
appC.add(myp);
}
}
class MyPanel extends JPanel {
public void paint(Graphics g)
{
g.setFont( new Font("Verdana", Font.BOLD , 18) ) ;
g.setColor(Color.green);
g.drawString("HELLO WORLD", 20, 20);
g.fillArc( 20, 50, 200, 200 , 0 , 90 ) ;
g.setColor( new Color(255, 128, 64) ) ;
g.fillArc( 20, 50, 200, 200 , 90 , 40 ) ;
g.setColor( Color.pink ) ;
g.fillArc( 20, 50, 200, 200 , 130 , 230 ) ;
}
}
现在我想取出第一个切片.. 仅将以下内容添加到 fillArc 方法的第一个参数(x 坐标)
(int) Math.round(Math.cos(put_first_value_here/360.0*Math.PI)*20)
仅将以下内容添加到 fillArc 方法的第二个参数(y 坐标)
-((int) Math.round(Math.sin(put_first_value_here/360.0*Math.PI)*20))
其中 first_value 是第一条圆弧的角度
和 html 文件:
<APPLET CODE="AppDemo.class" CODEBASE="." WIDTH=500 HEIGHT=500>
<param name=adds value=1100 />
<param name=memberships value=300/>
<param name=sales value=1000/>
</APPLET>
html文件结束
他们告诉我使用构造函数来获取值,但我不知道该怎么做,也不明白为什么要使用它
提前致谢
【问题讨论】:
-
对那个编辑破坏者感到抱歉。