Applet并没有发挥应有的作用

时间:2015-10-16 08:11:29

标签: java applet

所以我不知道为什么我的applet不能正常工作,它没有显示它刚刚显示的链接,就像你刚刚从eclipse运行它一样。 我是这个applet的新手,我不懂HTML。 这是video tutorial

import java.net.*;
import java.util.*;
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.event.*;

public class BuckySites extends JApplet {

    private HashMap<String, URL> websiteInfo;
    private ArrayList<String> titles;
    private JList mainList;

//init
public void init(){
    websiteInfo = new HashMap<String, URL>();
    titles = new ArrayList<String>();

    grabHTMLInfo();
    add(new JLabel("What website do you want to visit?"), BorderLayout.NORTH);
    mainList = new JList(titles.toArray());

    mainList.addListSelectionListener(
            new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent event) {
                    Object object = mainList.getSelectedValue();
                    URL newDocument = websiteInfo.get(object);
                    AppletContext browser = getAppletContext();
                    browser.showDocument(newDocument);
                }
            }
    );
    add(new JScrollPane(mainList), BorderLayout.CENTER);
}
//get html info
private void grabHTMLInfo() {
    String title;
    String address;
    URL url;
    int counter = 0;
    title = getParameter("title"+counter);

    while(title != null){
        address = getParameter("address"+counter);
        try{
            url = new URL(address);
            websiteInfo.put(title, url);
            titles.add(title);
        }catch(MalformedURLException urlException){
            urlException.printStackTrace();
        }
        ++counter;
        title = getParameter("title"+counter);
    }
}
}

,html文件是

<html>
<body>
    <applet code="BuckySites.class" width="500" height="250">
        <param name="title0" value="utube.com">
        <param name="adress0" value="https://www.youtube.com/">
        <param name="title1" value="9gag.com">
        <param name="adress1" value="http://9gag.com/">
    </applet>
</body>

0 个答案:

没有答案