I have a bidder class for a car auction and cannot seem to pass jtextfield values into the array when the user clicks the submit button. The bidder class is:
package abc;
import java.util.ArrayList;
public class Bidder extends User{
private String firstName, lastName, street, city, postcode, tel, eMail, cardMake, cardNo, expDate;
private int houseNo, csvNo;
public Bidder(){
}
public Bidder(String UN, String UP, int UT, String FN, String LN, int HN,
String S, String C, String P, String T, String EM, String CM, String CN, String ED, int CSV ){
super (UN, UP, UT);
firstName = FN;
lastName = LN;
houseNo = HN;
street = S;
city = C;
postcode = P;
tel = T;
eMail = EM;
cardMake = CM;
cardNo = CN;
expDate = ED;
csvNo = CSV;
}
static ArrayList<Bidder> BidderArray = new ArrayList<Bidder>();
}
The values I am trying to pass to the array are as when a submit button is pressed are as follows:
private void submitActionPerformed(java.awt.event.ActionEvent evt) {
boolean validEntries = true;
String checkUserName = userName.getText();
if (checkUserName.equals(""))
{
validEntries = false;
userName.setBackground(Color.red);
}
String checkPassword = password.getText();
if (checkPassword.equals(""))
{
validEntries = false;
password.setBackground(Color.red);
}
try{
int checkUserType = Integer.parseInt(userType.getText());
}
catch (Exception error)
{
validEntries = false;
userType.setBackground(Color.red);
}
String checkFirstName = firstName.getText();
if (checkFirstName.equals(""))
{
validEntries = false;
firstName.setBackground(Color.red);
}
String checkLastName = lastName.getText();
if (checkLastName.equals(""))
{
validEntries = false;
lastName.setBackground(Color.red);
}
try
{
int checkHouseNo = Integer.parseInt(houseNo.getText());
}
catch (Exception error)
{
validEntries = false;
houseNo.setBackground(Color.red);
}
String checkStreet = street.getText();
if (checkStreet.equals(""))
{
validEntries = false;
street.setBackground(Color.red);
}
String checkCity = city.getText();
if (checkCity.equals(""))
{
validEntries = false;
city.setBackground(Color.red);
}
String checkPostcode = postcode.getText();
if (checkPostcode.equals(""))
{
validEntries = false;
postcode.setBackground(Color.red);
}
String checkTel = tel.getText();
if (checkTel.equals(""))
{
validEntries = false;
tel.setBackground(Color.red);
}
String checkEMail = eMail.getText();
if (checkEMail.equals(""))
{
validEntries = false;
eMail.setBackground(Color.red);
}
String checkCardType = cardType.getText();
if (checkCardType.equals(""))
{
validEntries = false;
cardType.setBackground(Color.red);
}
String checkCardNo = cardNo.getText();
if (checkCardNo.equals(""))
{
validEntries = false;
cardNo.setBackground(Color.red);
}
String checkExpDate = expDate.getText();
if (checkExpDate.equals(""))
{
validEntries = false;
expDate.setBackground(Color.red);
}
try
{
int checkCSV = Integer.parseInt(csv.getText());
}
catch (Exception error)
{
validEntries = false;
csv.setBackground(Color.red);
}
Bidder bidder2 = new Bidder(userName, password, userType, firstName, lastName, houseNo,
street, city, postcode, tel, eMail, cardType, cardNo, expDate, csv);
Bidder.BidderArray.add(bidder2);
}
Regards
Lee
userName,password, etc. correct before you pass them to the constructor?submitActionPerformedbeing called? Or is it being called? (As an ised, insidesubmitActionPerformed, shouldn't you be constructing and inserting the newBidderobject only whenvalidEntriesistrue?)