为什么Java小程序不是';t显示?

为什么Java小程序不是';t显示?,java,html,netbeans,applet,Java,Html,Netbeans,Applet,我正在尝试用JavaApplet构建一个非常简单的程序 当用户单击小程序窗口中显示的链接时,程序应导航到相应的网站。 但在我的情况下,没有小程序窗口弹出弹出一个窗口(下图)(只要我运行代码),这与我的程序无关 .java: package stringpractice; import java.awt.*; import java.applet.*; import javax.swing.*; import javax.swing.event.*; import java.util.*

我正在尝试用JavaApplet构建一个非常简单的程序

当用户单击小程序窗口中显示的链接时,程序应导航到相应的网站。

但在我的情况下,没有小程序窗口弹出弹出一个窗口(下图)(只要我运行代码),这与我的程序无关

.java:

    package stringpractice;

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

public class Applet extends JApplet {
    private HashMap<String,URL>websiteInfo;
    private ArrayList<String>titles;
    private JList mainList;

    private void inIt(){
        websiteInfo =new HashMap<String, URL>();
        titles =new ArrayList<String>();
        grabHTMLInfo();

        add(new JLabel("What website u wanna visit?"),BorderLayout.NORTH);
        mainList=new JList(titles.toArray());

        mainList.addListSelectionListener(


        new ListSelectionListener() {

            //@Override
            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);

    }
    private void grabHTMLInfo(){
        String title;
        String address;
        int counter=0;
        URL url;
        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>
<title>testing applet</title>

<body>

<applet code="Applet.class" width="500" height="200">

<param name="title0" value="Google">
<param name="address0" value="https://www.google.com/?gfe_rd=cr&ei=M8ovVKu9AujJ8gfH8oH4Cw">


<param name="title1" value="Yahoo">
<param name="address1" value="https://se.yahoo.com/">



</applet>

</body>



</html>

测试小程序

您的
init()
方法写为
init()
。由于所有内容都区分大小写,因此不会调用init方法。

将init方法声明更改为:
public void init()
applet不应该有
main
methoduser432,这更糟糕。没用。它所做的只是停止显示applet窗口(在我添加public之后)。
<html>
<title>testing applet</title>

<body>

<applet code="Applet.class" width="500" height="200">

<param name="title0" value="Google">
<param name="address0" value="https://www.google.com/?gfe_rd=cr&ei=M8ovVKu9AujJ8gfH8oH4Cw">


<param name="title1" value="Yahoo">
<param name="address1" value="https://se.yahoo.com/">



</applet>

</body>



</html>