1 Replies - 1264 Views - Last Post: 24 October 2005 - 06:53 PM Rate Topic: -----

#1 Rk47  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 11-October 05

Question about making numfields

Posted 24 October 2005 - 06:15 PM

Hello everyone !!!!

In my programming assignment , I have been asked to make a game applet, and it has 4 input of digits in 4 different fields. My question is that , do I create the fields like this ......

JTextField numField = new JTextField(10);
JTextField numField2 = new JTextField(10); and so on like numfield3 and numfield4 ... ??

And also when con.add(numfield) , do i have to specify like numfield1 and so on ?.

Oh and also teh same thing with label...

JLabel value = new JLabel(); do i do the same thing like make value1 and value2 and so on ?


And if so , then do I have to assign the value1 to numfield1 or it will be automatic ????

I am sorry if I didn't make teh question clear , but I hope u get the point . Thanks alot.


Any good websites regarding this ?

Is This A Good Question/Topic? 0
  • +

Replies To: Question about making numfields

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Question about making numfields

Posted 24 October 2005 - 06:53 PM

Yes, if you are declaring a new instance of a variable, you have to explicitly make the declaration. That means if you want a variable named numfield2, you have to declare it as you've mentioned.

And yes, when you call the .Add() method of the con object, you have to do it for each variable you wish to add. Of course, you can do this in a loop, or even make an array of numfield variables.

The same hold true for labels.

As for assigning the values, if you wish numfield1 to have the value of stored in value1, you have to assign it. It is not automatic.

Each of these variables is a separate instance on it's own, and must be treated as such unless you plan to write your oen class to do automatic assigments and variable generation.

There are many good websites regarding Java, inlcuding here, here and here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1