【问题标题】:Displaying an applet in HTML在 HTML 中显示小程序
【发布时间】: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文件结束

他们告诉我使用构造函数来获取值,但我不知道该怎么做,也不明白为什么要使用它

提前致谢

【问题讨论】:

  • 对那个编辑破坏者感到抱歉。

标签: java html applet


【解决方案1】:

如果我理解正确,您希望从您的小程序中访问 &lt;param.../&gt; 标记中包含的值。小程序可以通过getParameter(String) 方法访问这些参数。您通常在 init() 方法中访问这些值:

public class AppDemo extends JApplet
{
    public void init()
    {
        String adds = getParameter("adds");
        String memberships = getParameter("memberships");
        String sales = getParameter("sales");

        // The rest of your init() code...
    }
}

【讨论】:

    【解决方案2】:

    谷歌教程..例如http://www.dgp.toronto.edu/~mjmcguff/learn/java/

    阅读、理解、适应、测试 => 交作业..

    【讨论】:

      猜你喜欢
      • 2012-02-16
      • 2016-05-28
      • 2023-03-07
      • 1970-01-01
      • 2011-08-12
      • 2011-05-18
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      相关资源
      最近更新 更多