|
Barra di navigazione con etichette e link parametrici
Codice Html<applet code="JAppletURL.class" width="200" height="30"> <param name="etic1" value="Java"> <param name="link1" value="http://www.valentinocondoluci.it/appunti/java"> <param name="etic2" value="Html"> <param name="link2" value="http://www.valcon.it/htmleco"> <param name="etic3" value="IOI"> <param name="link3" value="http://www.valcon.it/ioi"> </applet> oppure
Codice Html<applet code="JAppletURL.class" width="450" height="40"> <param name="etic1" value="la Repubblica"> <param name="link1" value="http://www.repubblica.it"> <param name="etic2" value="Corriere della Sera"> <param name="link2" value="http://www.corriere.it"> <param name="etic3" value="LA STAMPA"> <param name="link3" value="http://www.lastampa.it"> </applet> Codice Javaimport java.awt.*; import java.awt.event.*; import java.net.*; import javax.swing.*; public class JAppletURL extends JApplet implements ActionListener { String l1, l2, l3, //link e1, e2, e3; //etichette URL u1, u2, u3; //url public void init() { l1=getParameter("link1"); e1=getParameter("etic1"); l2=getParameter("link2"); e2=getParameter("etic2"); l3=getParameter("link3"); e3=getParameter("etic3"); try { u1=new URL(l1); u2=new URL(l2); u3=new URL(l3); } catch(MalformedURLException ex) { System.out.println("Problemi con i parametri?"); } JPanel p=new JPanel(); JButton b1=new JButton(e1); b1.addActionListener(this); p.add(b1); JButton b2=new JButton(e2); b2.addActionListener(this); p.add(b2); JButton b3=new JButton(e3); b3.addActionListener(this); p.add(b3); add(p); } public void actionPerformed(ActionEvent ae) { String nome=ae.getActionCommand(); if(nome.equals(e1)) getAppletContext().showDocument(u1); else if(nome.equals(e2)) getAppletContext().showDocument(u2); else if(nome.equals(e3)) getAppletContext().showDocument(u3); else System.out.println("Problemi con i pulsanti?"); } } Osserva <param name="..." value="..."> getParameter() URL, MalformedURLException getAppletContext().showDocument() |
|