java - double array loses its information -



java - double array loses its information -

i writing little programme swing components class , have problem storing info within double array. programme works want 1 exception: i'm declaring array via "public double [] noten;" outside private methods of actionlisteners. array initiated within private method.

[...] public double summe, notenschnitt; public int i, anzahlnoten, bestenote, schlechtestenote; public double [] noten; private void jbÜbernehmen2actionperformed(java.awt.event.actionevent evt) { if(!jtanzahlnoten.gettext().equals("") && double.parsedouble(jtanzahlnoten.gettext())>=1 && double.parsedouble(jtanzahlnoten.gettext())<=5){ i++; //counts clicks decimalformat f = new decimalformat("#0.00"); summe = summe + double.parsedouble(jtnote.gettext()); //sum calculating mean anzahlnoten = integer.parseint(jtanzahlnoten.gettext()); //amount of grades noten = new double[anzahlnoten]; noten[i-1] = double.parsedouble(jtnote.gettext()); jlanoten.settext("noten: "); jlanoten.setvisible(true); for(double ae: noten){ jlanoten.settext(jlanoten.gettext()+" "+ae); } notenschnitt = summe / i; jlbn.setvisible(true); jlnn.setvisible(true); jlsn.setvisible(true); jlna.setvisible(true); jlnn.settext(f.format(notenschnitt)); jlna.settext(integer.tostring(i)); jlnote.settext(i+". note"); if(integer.parseint(jtnote.gettext()) < bestenote){ //gets best grade bestenote=integer.parseint(jtnote.gettext()); jlbn.settext(integer.tostring(bestenote)); } if(integer.parseint(jtnote.gettext()) > schlechtestenote){ //gets worst grade schlechtestenote=integer.parseint(jtnote.gettext()); jlsn.settext(integer.tostring(schlechtestenote)); } if (i >= integer.parseint(jtanzahlnoten.gettext())) { //if clicks = amount of grades -> stop jbÜbernehmen2.setvisible(false); jbneueberechnung.setvisible(true); jtnote.setbackground(color.light_gray); jtnote.setfocusable(false); }else{ jtnote.requestfocus(); jtnote.settext(""); } } } [...]

this not whole code, crucial part

expectation: foreach loop supposed give grades have entered. example: 3 grades should entered , come in 1,2 , 3. @ end line should give: "noten: 1.0, 2.0, 3.0"

but instead @ first click gives: "noten: 1.0, 0.0, 0.0". sec click: "noten: 0.0, 2.0, 0.0" 3rd click: "noten: 0.0, 0.0, 3.0".

it prints recent entered grade, why ? variable array declared public ?! don't it...

you maintain re-initializing array before putting new value in :

noten = new double[anzahlnoten]; noten[i-1] = double.parsedouble(jtnote.gettext());

make sure phone call noten = new double[anzahlnoten]; once.

for example, can initialize array when declare :

public double [] noten = new double[somefixedlength];

java arrays swing

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -