Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33
  1. #21
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Default Re: Help, please. I don't understand these error messages.

    Ah, okay. And I fix that by calling it BmiFrame.gewicht?
    Last edited by DarkExperience; 12-05-2011 at 08:29 PM.

  2. #22
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Help, please. I don't understand these error messages.

    Or simply just gewicht

  3. #23
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Default Re: Help, please. I don't understand these error messages.

    Hm, thanks :). I'll try that. But: I've done exactly the same with my height variable (with float in front of the variable's name) and it recognises the height. Why would it treat the two differently?

  4. #24
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Help, please. I don't understand these error messages.

    Post the code for setting the height

  5. #25
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Default Re: Help, please. I don't understand these error messages.

    Ah, it works! I don't know why but it works . Thanks so much !

    It doesn't really matter anymore but this is the height and the weight:

    Java Code:
    public void actionPerformed (ActionEvent e) {
        String gewichtString = gewichtEingabe.getText().trim();
        gewicht = Float.parseFloat(gewichtString);
        String größeString = größeEingabe.getText().trim();
        float größe = Float.parseFloat(größeString);
    }
    EDIT: No wait. It doesn't work. I had only used an older version of the program which had been set up a bit differently and therefore made me believe it had actually gotten the weight right. But no, it didn't. Sorry
    Last edited by DarkExperience; 12-05-2011 at 08:38 PM.

  6. #26
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Help, please. I don't understand these error messages.

    Post all of BmiFrames code that you are working on now

  7. #27
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Default Re: Help, please. I don't understand these error messages.

    Okay, wait. I got a bit confused with all the different back-ups of the program I've got. So, I've done these edits to the latest version and it now recognises the weight. However, as the result of my BMI calculation it now returns NaN (It's never done that before). What does that mean?

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    //Die für ein Fenster nötigen Datenpakete werden importiert
    public class BmiFrame extends Frame
      implements ActionListener, WindowListener {
      //Die Klasse BmiFrame wird als eine Erweiterung der Klasse Frame mit einem ActionListener und einem WindowListener erstellt
      private BMI meinBMI = null;
      public static float gewicht = 0.0f;
      public static float größe = 0.0f;
      public float FBmi = 0.0f;
      //Die benötigten Variablen werden erstellt. Ihnen werden ihre Startwerte zugewiesen
      private Label gewichtText = new Label("Gewicht in kg eingeben");
      private TextField gewichtEingabe = new TextField("00");
      private Label größeText = new Label("Größe in m eingeben");
      private TextField größeEingabe = new TextField("00");
      private Button berechnenButton = new Button("BMI berechnen");
      private Label bmiText = new Label("Ihr BMI");
      //Die Labels, Buttons und Textfelder des Fensters werden erstellt. Ihnen werden ihre Startwerte zugewiesen
      private GridLayout fensterLayout = new GridLayout (3,2);
      //Die Aufteilung/das Layout des Fensters wird bestimmt (3 Zeilen, 2 Spalten)
      private DecimalFormat wertFormat = new DecimalFormat("0.##");
      //Die Formatierungen der Zahlenwerte wird angegeben
      public void setBMI (BMI b) {
        this.meinBMI = b;
      }
      public BMI getBMI() {
        return meinBMI;
      }
      //Mit der Methode getBMI wird das Objekt meinBMI der Klasse BMI zurückgegeben
      public void init () {
        float gewicht = BMI.getGewicht();
        String gewString = wertFormat.format(gewicht);
        gewichtEingabe.setText(gewString);
        float größe = BMI.getGröße();
        String gröString = wertFormat.format(größe);
        größeEingabe.setText(gröString);
      //Den Textfeldern GewichtEingabe und GrößeEingabe wird der Wert der Floats Gewicht und Größe zugewiesen (welche zuvor aus meinBMI importiert und in Strings umgewandelt werden)
        this.setSize(300,125);
        this.setTitle("BMI-Rechner");
      //Größe und Titel des Fensters werden festgelegt
        this.setLayout(fensterLayout);
        this.add(gewichtText);
        this.add(gewichtEingabe);
        this.add(größeText);
        this.add(größeEingabe);
        this.add(bmiText);
        this.add(berechnenButton);
      //Die einzelnen Module werden in das zuvor bestimmte Fensterlayout eingeordnet
        berechnenButton.addActionListener(this);
        this.addWindowListener(this);
      //Dem BerechnenButton wird ein ActionListener angehängt
      }
      
      public void actionPerformed (ActionEvent e) {
        String gewichtString = gewichtEingabe.getText().trim();
        gewicht = Float.parseFloat(gewichtString);
        String größeString = größeEingabe.getText().trim();
        größe = Float.parseFloat(größeString);
      //Die vom User eingegebenen Werte werden zunächst Strings zugewiesen, welche dann in Floats umgewandelt werden
        Object angeklickt = e.getSource();
        if (angeklickt == berechnenButton) {
          BMI.berechnen();
      //Bei Klicken des berechnenButtons wird die Methode meinBMI.berechnen() ausgelöst
        float FBmi = BMI.getBmis();
        String bmiString = wertFormat.format(FBmi);
        bmiText.setText(bmiString);
        System.out.println(gewicht);
        System.out.println(größe);
        System.out.println(FBmi);
        //Der Wert der Variable BMI.getBmis wird dem Float FBmi zugewiesen. Dieses wird anschließend in den String bmiString umgewandelt, welcher als Inhalt für das TextField bmiText angegeben wird
        }
      }
      public static float getGewicht() {
        return BmiFrame.gewicht;
      }
      //Mit der Klasse getGewicht wird das Float BmiFrame.gewicht zurückgegeben
      public static float getGröße() {
        return BmiFrame.größe;
      }
      //Mit der Klasse getGewicht wird das Float BmiFrame.größe zurückgegeben
      public void windowClosing (WindowEvent e) {
        this.setVisible(false);
        System.exit(0);
      }
        public void windowClosed (WindowEvent e) { }
        public void windowOpened (WindowEvent e) { }
        public void windowIconified (WindowEvent e) { }
        public void windowDeiconified (WindowEvent e) { }
        public void windowActivated (WindowEvent e) { }
        public void windowDeactivated (WindowEvent e) { }
        //Dem Fenster selbst werden seine Zustände/Funktionen zugewiesen
    }
    Sorry for the German commentary.

  8. #28
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Help, please. I don't understand these error messages.

    NaN = not a number. Can I see the calculation code?

  9. #29
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Default Re: Help, please. I don't understand these error messages.

    Just the calculation method or the whole BMI class?
    Last edited by DarkExperience; 12-05-2011 at 08:53 PM.

  10. #30
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Help, please. I don't understand these error messages.

    Better make it the whole class :)

  11. #31
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Default Re: Help, please. I don't understand these error messages.

    Ah! I also had float in front of my variables in the calculation method. Removed those floats and now it's working (for real this time )! Thanks so much!
    Last edited by DarkExperience; 12-05-2011 at 08:56 PM.

  12. #32
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Help, please. I don't understand these error messages.

    Ok good stuff. Your code could be alot cleaner and have less redundancy. I would suggest, giving yourself a refresher on using static variables and using them in other classes. Also a good refresher on the scope of variables aswell. Best of luck.

  13. #33
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Default Re: Help, please. I don't understand these error messages.

    TBH, I don't think I'm ever going to use Java again (not because I don't like it but simply because I don't think I'll be needing it in the future). It was just for this computer science project at school and we've already kind of moved on from Java. Thanks, though .

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 8
    Last Post: 04-19-2011, 07:27 AM
  2. Cannot figure out error messages
    By Teclis in forum New To Java
    Replies: 6
    Last Post: 03-29-2011, 10:31 PM
  3. [SOLVED] error messages
    By raghu9198 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-10-2008, 07:21 AM
  4. Error Messages Not Showing Up
    By nvidia in forum Web Frameworks
    Replies: 0
    Last Post: 04-07-2008, 11:41 PM
  5. Jsf Error Messages - Retain
    By vaswin in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 08-05-2007, 09:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •