applet小应用程序需要使用appletviewer来看

解决方案 »

  1.   

    需要你写个html,里面调用applet的
      

  2.   

    1、Applet要用appletviewer和浏览器看
    2、源代码中有一点错误3、源代码
    //example.java :import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class example extends Applet implements ItemListener
    { Choice choice1,choice2;
    TextField text1=new TextField(),text2=new TextField();
    public void init()
    {
    setLayout(new GridLayout(2,2));
    choice1=new Choice();
    choice2=new Choice();
    choice1.add("Music Hall");
    choice1.add("Wushu Palace");
    choice1.add("Chess Garden");
    choice1.add("Chart");
    choice2.add("Liaoling Daily");
    choice2.add("BeiJing Daily");
    choice2.add("Shanghai Daily");
    choice2.add("Football Papar");
    add(choice1);
    add(choice2);
    add(text1);
    add(text2);
    choice1.addItemListener(this);
    choice2.addItemListener(this);
    }

    public void itemStateChanged(ItemEvent e)
    {
    if (e.getItemSelectable()==choice1)
    {
    if(choice1.getSelectedIndex()==0)
    {text1.setText("violin:The Died Bufferfly");}
    else if(choice1.getSelectedIndex()==1)
    {text1.setText("ShaoLinsi:Shaolin boxing");}
    else if(choice1.getSelectedIndex()==2)
    {text1.setText("Friendship");}
    else if(choice1.getSelectedIndex()==3)
    {text1.setText("Heart Friends");}
    }

    else if(e.getItemSelectable()==choice2)
    {
    if(choice2.getSelectedIndex()==0)
    {text2.setText("Good Information");}
    else if(choice2.getSelectedIndex()==1)
    {text2.setText("Six Everyday");}
    else if(choice2.getSelectedIndex()==2)
    {text2.setText("Hard to see");}
    else if(choice2.getSelectedIndex()==3)
    {text2.setText("Ball Fans Club");}
    }
    }
    }4、编译
    F:\java>javac example.java5、写web.html文件,文件和类文件在同一目录中
    <HTML>
    <applet
    code=example
    width=300
    height=200>
    </applet>
    </HTML>6、用appletviewer看或直接用浏览器看
    F:\java>appletviewer web.html
      

  3.   

    运行后appletviewer 显示:未初始化小应用程序!!!还是不能显示列表匡!!怎么办?谢谢指教!!
      

  4.   

    我试了一下可以呀,这种错误没有找到CLASS文件,你按照上面的方法一步一步来
    应该不会有错。