简体   繁体   English

为什么Java Applet无法显示?

[英]Why Java Applet isn't displaying?

I am trying to build a very simple program with java applet. 我正在尝试使用Java小程序构建一个非常简单的程序。

The program should navigate to corresponding website as an user click on their links which are appearing on the applet window. 当用户单击小程序窗口中显示的链接时,该程序应导航到相应的网站。

But in my case no applet window is popping up! 但就我而言,没有弹出任何小程序窗口! Well there is a window popping up (below is the image) 好吧,弹出一个窗口(下面是图片) 弹出窗口 (as soon as I run the code) which is not the relevant with my program. (一旦我运行代码)就与程序无关。

.java: .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);
        }



    }


}

.java main: .java主要:

package stringpractice;

public class appletMain {

    public static void main(String[] args) {

    }

}

.HTML: .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>

Your init() method is written as inIt() . 您的init()方法编写为inIt() As everything is case sensitive, your init method gets never called. 由于所有内容都区分大小写,因此永远不会调用您的init方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM