如果写在html里了就不用appletviewer了,appletviewer直接运行.class文件

解决方案 »

  1.   

    偶已经说过一次了~~~http://community.csdn.net/Expert/topic/3305/3305818.xml?temp=.7176935
      

  2.   


    Januarius_(要考研了:() :
    如果写在html里了就不用appletviewer了,appletviewer直接运行.class文件
    ---------------------------------------------------------------------------------
    用appeltviewer运行Applet和用Browser运行Applet是一样的效果,而且都必须将.class文件嵌入到html中才可以运行。To 楼主:1、编译是编译,运行是运行,编译通过了,不一定能正常运行。
    2、建议把Applet代码和html都贴出来看一下。
      

  3.   

    编译是编译,运行是运行,这个我知道,但编译都通过了,还是运行不起。
    下面贴出我的源代码,还望高手帮我分析一下:
    (Converter.java)
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.applet.Applet;
    class Unit                                               //第一个类
    {
    String description;
    double multiplier;
    Unit(String description,double multiplier)       //类的构造函数
    {
    super();
    this.description=description;
    this.multiplier=multiplier;
    }
    }
    class CPanel extends Panel implements ActionListener,AdjustmentListener,ItemListener
                                                              //第二个类
    {
    TextField TEnter;
    Choice Cchoose;
    int max=10000;
    Converter handle;
    Unit[] units;
    CPanel(Converter myController,String myTitle,Unit[] myUnits)     {
    GridBagConstraints c=new GridBagConstraints();
    GridBagLayout gridbag=new GridBagLayout();
    setLayout(gridbag);
    handle=myController;                      //获取转换器对象
    units=myUnits;                            //获取单位对象的数组
    c.fill=GridBagConstraints.HORIZONTAL;     //将组件填满水平的显示区域
    Label l=new Label(myTitle,Label.CENTER);
    c.gridwidth=GridBagConstraints.REMAINDER;
    gridbag.setConstraints(l,c);
    add(l);
    TEnter=new TextField("0",10);
    c.weightx=1.0;
    c.gridwidth=1;
    gridbag.setConstraints(TEnter,c);
    add(TEnter);
    TEnter.addActionListener(this);            Cchoose=new Choice();
    for(int i=0;i<units.length;i++)
    {
    Cchoose.add(units[i].description);
    }
    c.weightx=0.0;
    c.gridwidth=GridBagConstraints.REMAINDER;
    gridbag.setConstraints(Cchoose,c);
    add(Cchoose);
    Cchoose.addItemListener(this);          c.gridwidth=1;
    }
    double getMultiplier()
    {
    int i=Cchoose.getSelectedIndex();
    return units[i].multiplier;
    }
    public void paint(Graphics g)
    {
    Dimension d=getSize();
    g.drawRect(0,0,d.width-1,d.height-1);
    }
    public Insets getInsets()
    {
    return new Insets(5,5,5,8);
    }
    double getValue()
    {
    double f;
    try
    {
    f=(double)Double.valueOf(TEnter.getText()).doubleValue();
    }
    catch(java.lang.NumberFormatException e)
    {
    f=0.0;
    }
    return f;
    }
    public void actionPerformed(ActionEvent e)
    {
    setSliderValue(getValue());
    handle.Exchange(this);
    }
    public void itemStateChanged(ItemEvent e)
    {
    handle.Exchange(this);
    }
    public void adjustmentValueChanged(AdjustmentEvent e)
    {
    TEnter.setText(String.valueOf(e.getValue()));
    handle.Exchange(this);
    }
    void setValue(double f)
    {
    setSliderValue(f);
    TEnter.setText(String.valueOf((float)f));
    }
    void setSliderValue(double f)
    {
    int SliderValue=(int)f;
    if(SliderValue>max)
    SliderValue=max;
    if(SliderValue<0)
    SliderValue=0;
    }
    }
    public class Converter extends Applet                     //第三个类
    {
    private CPanel MPanel,UPanel;
    private Unit[] ChoiceM=new Unit[3];
    private Unit[] ChoiceU=new Unit[4];
    public void init()                                //Applet类的初始化函数
    {
    setLayout(new GridLayout(2,0,5,5));
    ChoiceM[0]=new Unit("公分",0.01);
    ChoiceM[1]=new Unit("公尺",1.0);
    ChoiceM[2]=new Unit("公里",1000.0);
    MPanel=new CPanel(this,"公制",ChoiceM);
    MPanel.setBackground(Color.white);
    ChoiceU[0]=new Unit("英寸",0.0254);
    ChoiceU[1]=new Unit("英尺",0.305);
    ChoiceU[2]=new Unit("码",0.914);
    ChoiceU[1]=new Unit("英里",1613.0);
    UPanel=new CPanel(this,"英制",ChoiceU);
    UPanel.setBackground(Color.white);
    add(MPanel);
    add(UPanel);
    }
    void Exchange(CPanel from)
    {
    CPanel to;
    if(from==MPanel){
    to=UPanel;
    }else{
            to=MPanel;
    }
    double multiplier=from.getMultiplier();
    to.setValue(multiplier*from.getValue());
    }
    public void paint(Graphics g)
    {
    Dimension d=getSize();
    g.drawRect(0,0,d.width-1,d.height-1);
    }
    public Insets getInsets()
    {
    return new Insets(5,5,5,5);
    }
    } 相应的HTML文件:
    <html>
    <head>
    <title>单位转换器</title>
    </head>
    <body>
    <applet code="Converter.class" width=275 height=160>
    </applet>
    </body>
    </html>

    谢谢!!!