try { txtName.setBackground(Color.WHITE); double billTotal = Double.parseDouble(txtName.getText()); int totalPeople = Integer.parseInt(txtPeople.getText()); int incorrectName = 0; double tipPercent = Double.parseDouble(txtPercent.getText()); double tipAmount = billTotal * tipPercent/100; incorrectName = 1; double grandTotal = billTotal + tipAmount; incorrectName = 2; double totalperPerson = grandTotal / totalPeople; incorrectName = 3; DecimalFormat df = new DecimalFormat ("$0.00"); lblTip.setText("" + df.format(tipAmount)); lblGrandT.setText("" + df.format(grandTotal)); lblTP.setText("" + df.format(totalperPerson)); } catch(NumberFormatException a) { JOptionPane.showMessageDialog(null, "Please fill in the required fields!", "Invalid data!",JOptionPane.ERROR_MESSAGE); if (incorrectName == 0) { txtName.setBackground(Color.RED); txtPeople.setBackground(Color.WHITE); txtPercent.setBackground(Color.WHITE); } else if (incorrectName == 2) { txtName.setBackground(Color.WHITE); txtPeople.setBackground(Color.RED); txtPercent.setBackground(Color.WHITE); } else if (incorrectName == 3) { txtName.setBackground(Color.WHITE); txtPeople.setBackground(Color.WHITE); txtPercent.setBackground(Color.RED); } } }