Applet does not run in browser

4

Does not run the Applet. Just give that feedback.

Thisismyjavaclass.

publicclassSiteSelectorextendsJApplet{privateHashMap<String,URL>sites;//nomeseURLsdesiteprivateArrayList<String>siteNames;//nomesdesitesprivateJListsiteChooser;//listadositesaescolher//leosparametroseconfiguraaGUIpublicvoidinit(){sites=newHashMap<String,URL>();siteNames=newArrayList<String>();//otemosparametrosdodocumentoXHTMLgetSitesFormHTMLParmeters();//criacomponentesGUIeainterfacelayoutadd(newJLabel("Choose a stie to browser"), BorderLayout.NORTH);

    siteChooser = new JList(siteNames.toArray()); // preenche a JList
    siteChooser.addListSelectionListener(new ListSelectionListener() {
        //vai ao site selecionado pelo usuário
        @Override
        public void valueChanged(ListSelectionEvent arg0) {
            // TODO Auto-generated method stub

            //obtem o nome do site selecionado
            Object object = siteChooser.getSelectedValue();

            //utiliza o nome do site para localizar a URL correspondente
            URL newDocument = sites.get(object);

            //obtem o conteiner de applets 
            AppletContext browser = getAppletContext();

            //instrui o conteiner de applets a mudar as paginas
            browser.showDocument(newDocument);
        }
    }); // classe interna anonima

    add(new JScrollPane(siteChooser),BorderLayout.CENTER);
}

//obetem os paramentros do documento XHTML
private void getSitesFormHTMLParmeters(){
    String title; // titutlo do site
    String location = ""; // localização do site
    URL url; // URL da localização
    int counter = 0; // conta o nuemro de sites

    title = getParameter("title" + counter); // obtem o primeiro titulo do site

    //faz um loop até que não haja mais parametros no documento XHTML
    while(title != null){
        //obtem a localização do site
        location = getParameter("location" + location);

        try{//coloca titulo/URL no HashMap e titulo na ArrayList
            url = new URL(location); // converte a localização em URL
            sites.put(title,url); // coloca titulo/URL no HashMap
            siteNames.add(title); // coloca o titulo no ArrayList
        }catch(MalformedURLException urlException){
            urlException.printStackTrace();
        }
        ++counter;
        title = getParameter("title" + counter); // obtem o proximo titulo do site
    }
}

}

This is my HTML.

What am I doing wrong? The html file put it in the / bin directory with .class

    
asked by anonymous 22.08.2014 / 01:28

1 answer

3

Assuming you have not yet gotten the problem, I notice that in your HTML you have some errors that cause an incorrect or null view of your Applet.

Tag applet

Where you set the height, you have a writing error where heiht should be height :

<applet codebase="." code="solo.SiteSelector.class" width="300" heiht="75">
  <!-- ... -->
</applet>

Should be:

<applet codebase="." code="solo.SiteSelector.class" width="300" height="75">
  <!-- ... -->
</applet>

This can cause your applet to have height equal to zero, where although it is running, you end up not visualizing it.

Note:
As can be seen on documentation , this is a required attribute, which by itself, typing is sufficient to justify your problem.

Attribute% with%

In your attribute code in the tag code you have written:

code="solo.SiteSelector.class"

But since I do not know where applet comes from, judging by the code in your question you should only have:

code="SiteSelector.class"

You can view the documentation (English) the solo attribute is supposed to contain the class name, and your class is called code .

Note:
On the other hand, you can also pass SiteSelector , that is, packagename.classname.class as seen in documentation on this page (English) .
In your case it will be package meuPacote.minhaClasse.class and class solo if that is the reality.

Attribute% with%

The SiteSelector attribute is used to indicate the path to the files. The same is used in conjunction with the value of the codebase attribute.

In your case, you are indicating that the file is in:

./solo.SiteSelector.class

The codebase followed by the code should give a valid path, confirm if it is your case.

Tag .

In your second tag solo.SiteSelector.class you have the attribute that contains the value with the misspelled name:

<param name="location0" valeu="http://java.sun.com/">

Should be:

<param name="location0" value="http://java.sun.com/">

After the resolution above you may have the problem solved or you may have overtaken part of the problem.

Here are some ideas to better exploit the situation if you have just overcome part of the problem:

  • Change the background color of the param tab to see if the Applet is running or not, because the background should turn green and your Applet will have a different color background, probably white:

    <body bgcolor="green">
    
  • Normally browsers are 32Bit, but you already have 64Bit versions available, check if you are using the 32bit or 64bit version of Java and cross the information with the browser to see if they both share the same architecture.

  • Try your Applet with appletviewer ( English) you can run from the terminal:

    appletviewer meuFicheiro.html
    
  • 19.10.2014 / 19:20