Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    Apertura finestra browser con applet

    Ciao a tutti, ho una necessità che credo sia di facile soluzione pr qualcuno che conosce le applet java: all'interno di una funzione ho bisogno di un metodo x aprire una finestra del browser specificandogli la url, x esempio una cosa del genere:

    function apri()
    {

    .....

    metodoCheApreLaFinestraDelBrowser("www.html.it");
    /*codice che apre una finestra del browser alla home di html.it*/


    .....

    }

    Attendo risposta!

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2001
    Messaggi
    4
    prova ad utilizzare qusto comando.


    getAppletContext().showDocument ( url , "_self")

    _self = nella finestra corrente
    _blank = apre una nuova pagina del browser


    ciao

  3. #3
    Ci ho provato, il codice compila ma non apre nessuna finestra
    Può esserti d'aiuto se ti invio il codice?
    Fammi sapere ti prego!

  4. #4
    Ho controllato la console java, il problema è un null pointer exception...mi sa che inizializzo male la url che passo al metodo...ora provo a smanettarci un po...

  5. #5
    Niente, proprio non capisco cosa non gli piace....

  6. #6
    Utente di HTML.it
    Registrato dal
    Nov 2001
    Messaggi
    4
    ok, mandami il codice

  7. #7
    Ecco il codice:

    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.EventObject;
    import java.util.Random;

    public class QMOL extends Applet
    implements ActionListener
    {

    public void init()
    {
    setBackground(Color.blue);
    BorderLayout borderlayout = new BorderLayout();
    p = new Panel();
    p.setLayout(borderlayout);
    Font font = new Font("Arial", 1, 18);
    Panel panel = new Panel();
    la0 = new Label();
    la0.setFont(font);
    la0.setForeground(Color.blue);
    panel.add("North", la0);
    add(panel);
    Font font1 = new Font("Arial", 1, 13);
    b = new Button("Genera nuovi numeri");
    b.setFont(font1);
    b.addActionListener(this);
    p.add("South", b);
    add(p);
    GridLayout gridlayout = new GridLayout(3, 3);
    p1 = new Panel();
    p1.setLayout(gridlayout);
    t = new TextField("", 2);
    t.setBackground(Color.white);
    t1 = new TextField("", 2);
    t1.setBackground(Color.white);
    t2 = new TextField("", 2);
    t2.setEditable(false);
    t2.setBackground(Color.white);
    t2.setForeground(Color.red);
    t3 = new TextField("", 2);
    t3.setEditable(false);
    t3.setBackground(Color.white);
    t3.setForeground(Color.red);
    t4 = new TextField("", 2);
    t4.setEditable(false);
    t4.setBackground(Color.white);
    t4.setForeground(Color.red);
    t5 = new TextField("", 2);
    t5.setBackground(Color.white);
    t6 = new TextField("", 2);
    t6.setBackground(Color.white);
    t7 = new TextField("", 2);
    t7.setBackground(Color.white);
    t8 = new TextField("", 2);
    t8.setEditable(false);
    t8.setBackground(Color.white);
    t8.setForeground(Color.red);
    Font font2 = new Font("Arial", 1, 35);
    t.setFont(font2);
    t1.setFont(font2);
    t2.setFont(font2);
    t3.setFont(font2);
    t4.setFont(font2);
    t5.setFont(font2);
    t6.setFont(font2);
    t7.setFont(font2);
    t8.setFont(font2);
    p1.add(t);
    p1.add(t1);
    p1.add(t2);
    p1.add(t3);
    p1.add(t4);
    p1.add(t5);
    p1.add(t6);
    p1.add(t7);
    p1.add(t8);
    add(p1);
    BorderLayout borderlayout1 = new BorderLayout();
    p2 = new Panel();
    p2.setLayout(borderlayout1);
    la = new Label();
    Font font3 = new Font("Arial", 1, 13);
    la.setFont(font3);
    la.setForeground(Color.yellow);
    p2.add("North", la);
    b1 = new Button("Terminato");
    b1.addActionListener(this);
    Font font4 = new Font("Arial", 1, 13);
    b1.setFont(font4);
    p2.add("South", b1);
    add(p2);
    Genera();
    }

    public void Genera()
    {
    r = new Random();
    r.setSeed(System.currentTimeMillis());
    do
    {
    x = new Integer(r.nextInt());
    bt = new Byte(x.byteValue());
    } while(bt.byteValue() >= 99 || bt.byteValue() <= 4);
    i1 = new Integer(bt.intValue());
    i2 = new Integer(i1.intValue() - 3);
    i3 = new Integer(i1.intValue() - 1);
    i4 = new Integer(i1.intValue() - 4);
    som = new Integer(i1.intValue() + i2.intValue() + i3.intValue() + 1);
    la.setText("Somma = " + som.toString());
    n1 = new String(i1.toString());
    n2 = new String(i2.toString());
    n3 = new String(i3.toString());
    n4 = new String(i4.toString());
    t2.setText(n1);
    t3.setText(n2);
    t4.setText(n3);
    t8.setText(n4);
    la0.setText(" Risolvi il quadrato !");
    la0.setForeground(Color.orange);
    b1.setEnabled(true);
    t.setText("");
    t1.setText("");
    t5.setText("");
    t6.setText("");
    t7.setText("");
    }

    public void Controlla()
    {
    aut = new Integer(t.getText());
    but = new Integer(t1.getText());
    cut = new Integer(t5.getText());
    dut = new Integer(t6.getText());
    eut = new Integer(t7.getText());
    if(aut.intValue() + but.intValue() + i1.intValue() == som.intValue())
    {
    if(i2.intValue() + i3.intValue() + cut.intValue() == som.intValue())
    {
    if(dut.intValue() + eut.intValue() + i4.intValue() == som.intValue())
    {
    if(aut.intValue() + i3.intValue() + i4.intValue() == som.intValue())
    {
    if(i1.intValue() + i3.intValue() + dut.intValue() == som.intValue())
    {
    Vittoria();
    return;
    } else
    {
    la0.setText(" Errato, riprova !");
    return;
    }
    } else
    {
    la0.setText(" Errato, riprova !");
    return;
    }
    } else
    {
    la0.setText(" Errato, riprova !");
    return;
    }
    } else
    {
    la0.setText(" Errato, riprova !");
    return;
    }
    } else
    {
    la0.setText(" Errato, riprova !");
    return;
    }
    }

    public void actionPerformed(ActionEvent actionevent)
    {
    if(actionevent.getSource() == b)
    Genera();
    if(actionevent.getSource() == b1)
    Controlla();
    }

    public String getAppletInfo()
    {
    return "Magic Square On Line by Fabrizio Leonardi";
    }

    public void Vittoria()
    {
    URL indirizzo = null;
    String stringa = new String("http://www.google.it");
    /*la url di google è messa a esempio, io in realtà devo aprire un file html che sta sulla stessa directory di quello che contiene l'applet...devo mettere il percorso assoluto?*/
    try{
    indirizzo = new URL(stringa);
    } catch (Exception e){}
    getAppletContext().showDocument(indirizzo , "Esatto");
    la0.setText(" --> ESATTO ! <--");
    la0.setForeground(Color.yellow);
    b1.setEnabled(false);
    la.setForeground(Color.orange);
    }


    public QMOL()
    {
    }

    Button b;
    Button b1;
    Panel p;
    Panel p1;
    Panel p2;
    String n1;
    String n2;
    String n3;
    String n4;
    Integer x;
    Integer i1;
    Integer i2;
    Integer i3;
    Integer i4;
    Integer som;
    Integer aut;
    Integer but;
    Integer cut;
    Integer dut;
    Integer eut;
    Byte bt;
    Label la;
    Label la0;
    TextField t;
    TextField t1;
    TextField t2;
    TextField t3;
    TextField t4;
    TextField t5;
    TextField t6;
    TextField t7;
    TextField t8;
    Random r;
    }

    Il problema sta nella funzione in grasseto

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.