开发者

How can I display a variable in Java ME (not text just a variable)?

I am hoping someone can help me. I have a very simple question, but for the life of me I cannot seem to locate an answer: How can I display a variable in Java ME? I see TextFields, TextBoxes, ChoiceGroups, etc., all of which don't seem to allow me to display a specific variable (only text). Any help would be greatly appreciated. Below see a snipet of my code - which I might add is not working?

  else
  {
      mpg = ((endMileage - beginMileage)/ gallons;
      txtFld4= new TextField ("TOTAL MILES PER GALLON:"," ", 20, (int)mpg);
      form2.append(txtFld4);
      Display.getDisplay(this).setCurrent(form2);
  }

Of course, the a开发者_StackOverflowbove code stops in my Java Debugger on the instantiation of the txtFld4. I assume that it is notaccepting the 'mpg' variable.

Any guidance would be appreciated.


TextField(java.lang.String label, java.lang.String text, int maxSize, int constraints) 

You're doing it wrong, do:

txtFld4= new TextField ("TOTAL MILES PER GALLON:",""+mpg, 20, SOME_CONSTANT_FOR_TEXTFIELD_HERE);


What does it mean to display "a variable"? What would it look like to display a ServerSocket?

What you need to do is turn the variable into a String, and it can then be shown.

txtFld4 = new TextField("Total MPG: " + mpg.toString());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜