我正在尝试使用java applet构建一个非常简单的程序。
当用户点击小程序窗口中显示的链接时,程序应导航到相应的网站。
但在我的情况下,没有弹出小程序窗口! 嗯有一个窗口弹出(下面是图像)(一旦我运行代码)这与我的计划无关。
的.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:
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>
答案 0 :(得分:0)
您的init()
方法写为inIt()
。由于所有内容都区分大小写,因此永远不会调用init方法。