Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: Applet Java

  1. #1

    Applet Java

    Quando compilo il mio applet il compilatore non mi dà errori ma quando poi carico l' applet con IE, Opera o Netscape non ottengo nulla o solo il messaggio: applet crashes
    Cosa può essere successo?
    Grazie.

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    698
    di tutto

    posta qualche altra informazione

  3. #3
    Ok questo è l' applet:

    import java.awt.*;
    import java.applet.*;
    public class Calcolatrice extends Applet {
    private Button makeButton(String label,Color color) {//metodo ausiliario per creare i pulsanti
    Button b = new Button(label); //data l'etichetta e il colore
    b.setBackground(color);
    b.setFont(new Font("Courier", Font.BOLD, 10));
    return b;
    }
    private Panel makePanel(LayoutManager lm,Color c) {
    Panel p = new Panel();
    p.setLayout(lm);
    p.setBackground(c);
    return p;
    }
    private void makeButtons() {
    Color lightRed = new Color(255,100,100);
    Color lightBlue = new Color(100,100,255);
    Color yellow = new Color(255,255,100);

    c = makeButton("C",lightRed);
    eq = makeButton("=",lightBlue);
    div = makeButton("/",lightBlue);
    per = makeButton("*",lightBlue);
    meno = makeButton("-",lightBlue);
    più = makeButton("+",lightBlue);
    eq2 = makeButton("=",lightBlue);
    b1 = makeButton("1",yellow);
    b2 = makeButton("2",yellow);
    b3 = makeButton("3",yellow);
    b4 = makeButton("4",yellow);
    b5 = makeButton("5",yellow);
    b6 = makeButton("6",yellow);
    b7 = makeButton("7",yellow);
    b8 = makeButton("8",yellow);
    b9 = makeButton("9",yellow);
    bp = makeButton(".",yellow);
    }
    public void init() {
    background = new Color(200,255,255);
    this.setLayout(new FlowLayout(FlowLayout.CENTER,4,1));

    result = new Label("0.00000 ",Label.RIGHT);
    result.setBackground(new Color(255,255,255));
    add(result);
    makeButtons();

    row1 = makePanel(new FlowLayout(FlowLayout.LEFT,4,2),background);
    row1.add(c);
    row1.add(eq);
    row1.add(div);
    row1.add(per);

    row2 = makePanel(new FlowLayout(FlowLayout.LEFT,4,2),background);
    row2.add(b7);
    row2.add(b8);
    row2.add(b9);
    row2.add(meno);

    row3 = makePanel(new FlowLayout(FlowLayout.LEFT,4,2),background);
    row3.add(b4);
    row3.add(b5);
    row3.add(b6);
    row3.add(più);

    add(row1);
    add(row2);
    add(row3);

    p12 = makePanel(new BorderLayout(2,2),background);
    p12.add("West",b1);
    p12.add("East",b2);

    p120 = makePanel(new BorderLayout(2,2),background);
    p120.add("North",p12);
    p120.add("South",b0);

    p3p = makePanel(new BorderLayout(2,2),background);
    p3p.add("Norht",b3);
    p3p.add("South",bp);

    p3peq = makePanel(new BorderLayout(2,2),background);
    p3peq.add("West",p3p);
    p3peq.add("East",eq2);

    add(p120);
    add(p3peq);

    setBackground(background);
    }
    public void paint(Graphics g) {
    setSize(row1.getSize().width,8*b1.getSize().height );
    validate();
    }
    private Panel row1,row2,row3,p12,p120,p3p,p3peq;
    private Button c,eq,div,per,meno,più,b1,b2,b3,b4,b5,b6,b7,b8,b9,b 0,bp,eq2;
    private Color background;
    private Label result;
    }


    e questa è la pagina in cui dovrebbe visualizzarsi:

    <HTML>
    <HEAD>
    <TITLE> First page </TITLE>
    </HEAD>
    <BODY>
    <HR>
    <APPLET CODE="Calcolatrice.class" WIDTH=500
    HEIGHT=500></APPLET>
    <HR>
    </BODY>
    </HTML>

    ciao

  4. #4
    Utente di HTML.it L'avatar di Xadoom
    Registrato dal
    Dec 2002
    Messaggi
    1,491
    Hai provato a lanciarla con l'appletwiever per sapere se ci sono errori run-time?
    Windows Xp
    [Java]
    [PHP]Notepad++
    [Fortran90-77] elf90 g77
    [C++ /WinAPI] DevC++ VisualC++

  5. #5
    Scusate la mia ignoranza ma cos' è l' applet viewer? dove lo trovo?

  6. #6
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    698
    vai da prompt e scrivi appletviewer Calcolatrice

    si usa per testare le applet

  7. #7
    dunque ho provato ad utilizzare l'appletviewer e quello che ho ottenuto è:

    Microsoft Windows XP [Versione 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    D:\Documents and Settings\Pina>cd java

    D:\Documents and Settings\Pina\Java>appletviewer Calcolatrice
    Avviso: Impossibile leggere il file di proprietÓ di AppletViewer: D:\Documents a
    nd Settings\Pina\.hotjava\properties verranno utilizzati i valori di default.
    Eccezione di I/O durante la lettura: D:\Documents and Settings\Pina\Java\Calcola
    trice (Impossibile trovare il file specificato)

  8. #8
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    Riga 76:

    p120.add("South",b0);

    b0 non viene creato assieme agli altri pulsanti...
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

  9. #9
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    Linea 80: hai scritto "norht"
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

  10. #10
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    Correggi questi due e parte... ma tieniti pronto/a a chiudere il browser perchè non si comporta esattamente come dovrebbe...
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

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.