簡體   English   中英

為什么Java Applet無法顯示?

[英]Why Java Applet isn't displaying?

我正在嘗試使用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主要:

package stringpractice;

public class appletMain {

    public static void main(String[] args) {

    }

}

.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方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM