Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accepting values from JTextField & JCheckbox

Status
Not open for further replies.

asiavoices

Programmer
Sep 20, 2001
90
CA
Hello again everyone,

I was wondering what would be the best way of retrieving info entered on a form via a JTextField and JCheckBox(boolean) and passing them as an argument to a method I've created.

I believe I am close but I cannot get by the boolean (i.e JCheckbox) error message (at least that's where I think the error originates):

Error Message during compilation:

MyProgram.java [349:1] cannot resolve symbol
symbol : method booleanValue ()
location: class javax.swing.JCheckBox
Boolean theTaxState = new Boolean(isTaxField.booleanValue());

MyProgram.java [351:1] addItem (java.lang.String,double,boolean) in MyProgram cannot be applied to

(java.lang.String,double,java.lang.Boolean)
addItem(theName, thePrice, theTaxState);



/* ================================ */

Here's my code snippet:

JTextField descriptionField = new JTextField(15);
JTextField priceField = new JTextField(8);
JCheckBox isTaxField = new JCheckBox("Yes", true);

......

public void actionPerformed(ActionEvent theClickedEvent)
{
......
String theName = new String(descriptionField.getText());
double thePrice = new Double(priceField.getText()).doubleValue();
Boolean theTaxState = new Boolean(isTaxField.booleanValue());

/* ---- my method ------------->
addItem(theName, thePrice, theTaxState);
.......
} // end of actionPerformed



/* -------- addItem method() ----------- */

public void addItem(String name, double thePrice, boolean taxState)
{
ArrayList myStuff = new ArrayList();
Item cidx = new Item(name, thePrice, taxState);
myStuff.add(cidx);
numrecords++;

showList(myStuff);
......
}

Any help is greatly appreciated....

Cheers,

Christopher









 
2 mistakes:
1) Boolean is NOT the same as boolean. One is an object wrapper, one is a primative.
2) The method booleanValue() does not exist in JCheckBox. You want isSelected(). Check JavaDocs for more info.

So your example should be:
Code:
boolean theTaxState = isTaxField.isSelected();
The rest should work fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top