Feedback

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

import javax.swing.

*;

import javax.swing.border.LineBorder;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class BetterFeedbackForm extends JFrame {

private JTextField nameField, emailField;

private JTextArea feedbackArea;

private JComboBox<String> ratingComboBox;

private JCheckBox recommendCheckBox;

private JButton submitButton;

public BetterFeedbackForm() {

setTitle("Online Food Restaurant Feedback Form");

setSize(400, 300);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

try {

UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");

} catch (Exception e) {

e.printStackTrace();

initComponents();

private void initComponents() {

JPanel mainPanel = new JPanel(new GridBagLayout());

mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));


GridBagConstraints gbc = new GridBagConstraints();

gbc.insets = new Insets(5, 5, 5, 5);

gbc.gridx = 0;

gbc.gridy = 0;

mainPanel.add(new JLabel("Name:"), gbc);

nameField = new JTextField(20);

nameField.setFont(new Font("Arial", Font.PLAIN, 16));

nameField.setBorder(new LineBorder(Color.BLUE, 2));

gbc.gridx = 1;

mainPanel.add(nameField, gbc);

gbc.gridx = 0;

gbc.gridy = 1;

mainPanel.add(new JLabel("Email:"), gbc);

emailField = new JTextField(20);

emailField.setFont(new Font("Arial", Font.PLAIN, 16));

emailField.setBorder(new LineBorder(Color.BLUE, 2));

gbc.gridx = 1;

mainPanel.add(emailField, gbc);

gbc.gridx = 0;

gbc.gridy = 2;

mainPanel.add(new JLabel("Rating:"), gbc);

String[] ratings = {"5 Stars", "4 Stars", "3 Stars", "2 Stars", "1 Star"};

ratingComboBox = new JComboBox<>(ratings);

ratingComboBox.setFont(new Font("Arial", Font.PLAIN, 16));

ratingComboBox.setBorder(new LineBorder(Color.BLUE, 2));

gbc.gridx = 1;

mainPanel.add(ratingComboBox, gbc);
gbc.gridx = 0;

gbc.gridy = 3;

mainPanel.add(new JLabel("Recommend:"), gbc);

recommendCheckBox = new JCheckBox("Yes");

recommendCheckBox.setFont(new Font("Arial", Font.PLAIN, 16));

gbc.gridx = 1;

mainPanel.add(recommendCheckBox, gbc);

gbc.gridx = 0;

gbc.gridy = 4;

mainPanel.add(new JLabel("Feedback:"), gbc);

feedbackArea = new JTextArea(5, 20);

feedbackArea.setFont(new Font("Arial", Font.PLAIN, 16));

feedbackArea.setBorder(new LineBorder(Color.BLUE, 2));

JScrollPane scrollPane = new JScrollPane(feedbackArea);

gbc.gridx = 1;

gbc.weighty = 1.0;

gbc.fill = GridBagConstraints.BOTH;

mainPanel.add(scrollPane, gbc);

gbc.gridx = 0;

gbc.gridy = 5;

gbc.gridwidth = 2;

gbc.weighty = 0.0;

gbc.fill = GridBagConstraints.NONE;

submitButton = new JButton("Submit Feedback");

submitButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

submitFeedback();

}
});

submitButton.setFont(new Font("Arial", Font.BOLD, 18));

submitButton.setBackground(new Color(50, 150, 50));

submitButton.setForeground(Color.WHITE);

submitButton.setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));

mainPanel.add(submitButton, gbc);

add(mainPanel);

private void submitFeedback() {

String name = nameField.getText();

String email = emailField.getText();

String rating = (String) ratingComboBox.getSelectedItem();

boolean recommend = recommendCheckBox.isSelected();

String feedback = feedbackArea.getText();

// You can perform actions with the feedback data, such as sending it to a server or storing it in a
database.

// For now, let's just display the feedback in a dialog.

String feedbackMessage = "Name: " + name + "\nEmail: " + email + "\nRating: " + rating

+ "\nRecommend: " + (recommend ? "Yes" : "No") + "\nFeedback: " + feedback;

JOptionPane.showMessageDialog(this, feedbackMessage, "Feedback Submitted",


JOptionPane.INFORMATION_MESSAGE);

public static void main(String[] args) {

SwingUtilities.invokeLater(() -> {

BetterFeedbackForm feedbackForm = new BetterFeedbackForm();

feedbackForm.setVisible(true);

});
}

You might also like