java

Vollständige Seite anschauen…

man1ac

cpt. commander flame
Registriert
4. Februar 2004
Reaktionspunkte
0
Ort
Freiburg
hi kennt sich hier jemad mit java aus?

und zwar ist volgendest problem das proggi wird im applett ncih angezeit und ioch finde den fehler nciht

quellcode:

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class P extends Applet implements ActionListener {

private TextField eingabe1;
public double rabatt;
public double preiß;
public double proz;

public void init() {
Label feld1 = new Label ("Preis in Euro: ");
add(feld1);
eingabe1 = new TextField(10);
add(eingabe1);
eingabe1.addActionListener(this);

}

public void paint(Graphics g) {

rabatt= preiß*proz/100;
if (rabatt>=1)
g.drawString("Lohnt sich",50,50);
else
g.drawString("Lohnt sich nciht",50,50);
}

public void actionPerformed(ActionEvent event) {
Double temp1 = Double.valueOf(eingabe1.getText());

rabatt = temp1.doubleValue();

repaint();
}
}


schonmal vielen dank für eure hilfe
 
Vielleicht mal das Sonderzeichen "ß" durch ein normales "s" ersetzen. Haette dann auch den Vorteil, dass "Preis" richtig geschrieben ist
 
Hi,

so sieht's ganz gut aus. Wichtig ist die Zeile preiß = Double.parseDouble(eingabe1.getText()); in
paint()
. Jetzt kommt beim Start des Applets noch ein
Fehler, weil das Eingabefeld keinen Zahl enthaelt, aber das
ist ja simpel...

Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

/**
 *  Description of the Class
 *
 *@author     
 *@created    13. Juni 2005
 */
public class P extends Applet implements ActionListener {

    private TextField eingabe1;
    /**
     *  Description of the Field
     */
    public double rabatt;
    /**
     *  Description of the Field
     */
    public double preiß;
    /**
     *  Description of the Field
     */
    public double proz = 50;


    /**
     *  Description of the Method
     */
    public void init() {
        Label feld1 = new Label("Preis in Euro: ");
        add(feld1);
        eingabe1 = new TextField(10);
        add(eingabe1);
        eingabe1.addActionListener(this);

    }


    /**
     *  Description of the Method
     *
     *@param  g  Description of the Parameter
     */
    public void paint(Graphics g) {

        preiß = Double.parseDouble(eingabe1.getText());
        System.out.println("Preis: " + preiß);
        System.out.println("Proz: " + proz);
        rabatt = preiß * proz / 100;
        System.out.println("Rabatt: " + rabatt);
        if (rabatt >= 1) {
            g.drawString("Lohnt sich", 50, 50);
        } else {
            g.drawString("Lohnt sich nicht", 50, 50);
        }
    }


    /**
     *  Description of the Method
     *
     *@param  event  Description of the Parameter
     */
    public void actionPerformed(ActionEvent event) {
        Double temp1 = Double.valueOf(eingabe1.getText());

        // rabatt = temp1.doubleValue();

        repaint();
    }
}

Hier mein HTML:
Code:
<html>

<body>
<applet 
   code="P.class" codebase="." 
   alt="P-Applet"
   width="400" 
   height="400">

</applet>
</body>

</html>

hth,
knottyTom
 
Vollständige Seite anschauen…
Datenschutzeinstellungen