Menu Page
Menu Page
*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
public FoodMenuAppWithDifferentRestaurants() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setLayout(new BorderLayout());
createMenuItems();
userInfoPanel.add(nameLabel);
userInfoPanel.add(nameField);
userInfoPanel.add(mobileLabel);
userInfoPanel.add(mobileField);
userInfoPanel.add(addressLabel);
userInfoPanel.add(addressField);
createPlaceOrderButton(buttonPanel);
frame.add(userInfoPanel, BorderLayout.NORTH);
frame.add(buttonPanel, BorderLayout.SOUTH);
totalAmount = 0.0;
totalLabel.setForeground(Color.BLUE);
orderSummaryTextPane.setEditable(false);
orderSummaryTextPane.setForeground(Color.BLUE);
frame.add(totalLabel, BorderLayout.WEST);
frame.add(orderSummaryTextPane, BorderLayout.EAST);
initializeFoodPrices();
frame.setVisible(true);
String[] restaurants = {"Restaurant A", "Restaurant B", "Restaurant C", "Restaurant D"};
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.HORIZONTAL;
restaurantLabel.setForeground(Color.BLUE);
menuPanel.add(restaurantLabel, gbc);
createFoodQuantitySpinner(food);
menuPanel.add(foodLabel, gbc);
}
}
foodPrices.put("Burger", 5.0);
foodPrices.put("Pizza", 8.0);
foodPrices.put("Sushi", 10.0);
foodPrices.put("Pasta", 7.0);
foodPrices.put("Salad", 4.0);
foodPrices.put("Steak", 12.0);
// Modify this method to provide different food items for different restaurants
if (restaurant.equals("Restaurant A")) {
} else {
}
private void createFoodQuantitySpinner(String foodItem) {
gbc.fill = GridBagConstraints.HORIZONTAL;
spinner.addChangeListener(e -> {
totalAmount += itemTotal;
});
menuPanel.add(spinner, gbc);
placeOrderButton.addActionListener(new ActionListener() {
@Override
orderSummary.append("Order Summary:\n");
if (quantity > 0) {
orderSummary.append(foodItem + " from " + restaurant + ": " + quantity + " x $" +
price + " = $" + String.format("%.2f", quantity * price) + "\n");
orderSummary.append("THANK YOU!");
orderSummaryTextPane.setText(orderSummary.toString());
totalAmount = 0.0;
});
buttonPanel.add(placeOrderButton);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new FoodMenuAppWithDifferentRestaurants();
});