public void actionPerformed(ActionEvent event) { if (displayNutri.isSelected() && codeText.getText() != null) { // for Display Nutritional Info Button try { intValue2 = Integer.valueOf(codeText1.getText()); // Get the text value of Item Code } catch (NumberFormatException e) { display = "Enter Correct Item Code"; // Display Error Message for Wrong Input displayLabel.setForeground(Color.magenta); displayLabel.setText(display); codeText1.setText(null); return; } FoodItem item = DisplayNutritionalInfo(intValue2); // Call to the Method to Display Nutritional Info if (item != null) { calories = item.GetCalories(); // Get the nutrional Info of the Item Code from the FoodItem sugar = item.GetSugarContents(); fats = item.GetFatContents(); display = "Calorific Value = " + calories + " Sugar Contents = " + sugar + "gms" + " Fat Contents = " + fats + "gms"; displayLabel.setForeground(Color.magenta); displayLabel.setText(display); } else { display = "Enter Correct item Code"; // Display Error Message for Wrong Input displayLabel.setForeground(Color.magenta); displayLabel.setText(display); codeText.setText(null); } } if (querySuggest.isSelected() && calorieText.getText() != null) { // for Display Query Suggestion Button try { intValue2 = Integer.valueOf(calorieText.getText()); // Get the text value of Maximum Calorie Limit } catch (NumberFormatException e) { display = "Enter Correct Calorie Limit"; // Display Error Message for Wrong Input displayLabel.setForeground(Color.magenta); displayLabel.setText(display); calorieText.setText(null); return; } if (intValue2 < 0) { display = "Enter Correct Calorie Limit"; // Display Error Message for Wrong (negative) Input displayLabel.setForeground(Color.magenta); displayLabel.setText(display); calorieText.setText(null); } else { Hashtable itemList = DisplaySuggestion(); Enumeration e = itemList.elements(); String finalStr = ""; for (int i = 0; e.hasMoreElements(); i++) { // Get the list of Food items below the entered Calorie Limit VendingMachine.FoodStock stock = (VendingMachine.FoodStock) e.nextElement(); FoodItem item = stock.item; if (item.GetCalories() <= intValue2) { flag = 1; if (!finalStr.equals("")) { finalStr = finalStr + " , " + item.getDescription(); } else { finalStr = item.getDescription(); } } } if (flag == 1) { display = finalStr; // Display the list of Food items below the entered Calorie Limit displayLabel.setForeground(Color.magenta); displayLabel.setText(display); flag = 0; } else { display = "No items in the Machine below Calorie Limit " + intValue2; // No Items below the entered Calorie Limit displayLabel.setForeground(Color.magenta); displayLabel.setText(display); } } } }