4
Do not run Applet. Just give this return.
This is my java class.
public class SiteSelector extends JApplet {
private HashMap<String, URL> sites; // nomes e URLs de site
private ArrayList<String> siteNames; // nomes de sites
private JList siteChooser; // lista do sites a escolher
//le os parametros e configura a GUI
public void init(){
sites = new HashMap<String,URL>();
siteNames = new ArrayList<String>();
//otem os parametros do documento XHTML
getSitesFormHTMLParmeters();
//cria componentes GUI e a interface layout
add( new JLabel("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 I put in the /bin directory merged with . class
How are you opening this HTML file? Are you using a local server? Simply opening the HTML file in your browser? Your window reminds me a lot of the appletrunner (or apppletviewer, I don’t know - I haven’t touched Applets for years), you would be by chance using a command like this to try to open your applet?
– mgibsonbr
I am opening in the browser normally.
– Marcelo Viana
Type,
file:///caminho/pro/arquivo.html
?– mgibsonbr
That’s right. And it’s an example of a Deitel java book.
– Marcelo Viana
As much as I look, I can’t find the information whether or not to run an applet on the local file system, no server... I’m going to let someone with recent Java experience answer, so unfortunately I don’t really remember that detail.
– mgibsonbr
Tranquil mgibsonbr. I thank you for your attention.
– Marcelo Viana
The browser comes to ask you the execution permission questions for this applet?
– Ademir Mazer Jr - Nuno
Yes enough. I give the permission. And does not execute the applet. I already downloaded security and still can not run.
– Marcelo Viana
Try to put in the java settings the path to the file as safe or allowed website applet execution
– Ademir Mazer Jr - Nuno
Did you find a solution? Poste as an answer to help other people.
– Maniero