Wednesday, July 16, 2014

Autofill a JTextField once another JTextField has been typed into
































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Hi there
































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































I am trying to get a JTextField to autofill with the result of a calculation made from user input in another JTextField
































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































I am building a virtual ticket machine, where i want the user to select ticket type, type in the quantity of tickets they would like, and then so as soon as they have clicked out of the quantity textfield, I want the payment required textfield to autofil with the correct cost of the users selection, I have wrote the code to do the calculation for the cost, I just dont know how to put the cost in the payment required textfield at this stage.
































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Here is my code for this bit;
































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Java Code:











































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































public void actionPerformed(ActionEvent e) {

String TypeName = (String)TicketTypeList.getSelectedItem();
typeselectedTxt.setText(TypeName);
int arrayIndex = Arrays.asList(typeStrings).indexOf(TypeName);

String quantityStr = noOfTickets.getText();
Double quantity = Double.parseDouble(quantityStr);

if (noOfTickets.getText().equals(null) || noOfTickets.getText().equals("")){
showMessageDialog(null, "Please enter a quantity");

} else {

switch (arrayIndex){
case 0:
amountRequired = 15.00*quantity;
break;
case 1:
amountRequired = 10.20*quantity;
break;
case 2:
amountRequired = 5.70*quantity;
break;
case 3:
amountRequired = 30.85*quantity;
break;
}

moneyRequiredTxt.setText(Double.toString(amountRequired));


.....








































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































No comments:

Post a Comment