0% found this document useful (0 votes)
4 views6 pages

Java Mini Feedback Form Code

The document contains Java code for a graphical user interface (GUI) feedback form using Swing. It includes components such as labels, text fields, radio buttons for gender selection, a text area for feedback, checkboxes, and buttons for submission and clearing the form. The form validates user input and displays a confirmation dialog upon successful submission.

Uploaded by

iyasiniyasin90
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Java Mini Feedback Form Code

The document contains Java code for a graphical user interface (GUI) feedback form using Swing. It includes components such as labels, text fields, radio buttons for gender selection, a text area for feedback, checkboxes, and buttons for submission and clearing the form. The form validates user input and displays a confirmation dialog upon successful submission.

Uploaded by

iyasiniyasin90
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM:

import [Link].*;

import [Link].*;

import [Link].*;

public class FeedbackForm extends JFrame implements ActionListener {

// Components

JLabel nameLabel, genderLabel, feedbackLabel;

JTextField nameField;

JRadioButton maleButton, femaleButton;

JCheckBox agreeBox;

JButton submitButton, clearButton;

JTextArea feedbackArea;

ButtonGroup genderGroup;

// Constructor

FeedbackForm() {

// Frame setup

setTitle("User Feedback Form");

setSize(400, 500);

setLayout(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Name label and field

nameLabel = new JLabel("Name:");

[Link](50, 50, 100, 30);

nameField = new JTextField();

[Link](150, 50, 180, 30);

// Gender label and radio buttons

genderLabel = new JLabel("Gender:");

[Link](50, 100, 100, 30);

maleButton = new JRadioButton("Male");

femaleButton = new JRadioButton("Female");

[Link](150, 100, 70, 30);

[Link](230, 100, 80, 30);

genderGroup = new ButtonGroup();

[Link](maleButton);

[Link](femaleButton);

// Feedback label and area

feedbackLabel = new JLabel("Feedback:");

[Link](50, 150, 100, 30);

feedbackArea = new JTextArea();

[Link](150, 150, 180, 100);


[Link](true);

// Checkbox

agreeBox = new JCheckBox("I agree to submit");

[Link](120, 270, 180, 30);

// Buttons

submitButton = new JButton("Submit");

[Link](70, 320, 100, 40);

clearButton = new JButton("Clear");

[Link](200, 320, 100, 40);

// Add action listeners

[Link](this);

[Link](this);

// Add components to frame

add(nameLabel);

add(nameField);

add(genderLabel);

add(maleButton);

add(femaleButton);

add(feedbackLabel);
add(feedbackArea);

add(agreeBox);

add(submitButton);

add(clearButton);

setVisible(true);

// Event Handling

public void actionPerformed(ActionEvent e) {

if ([Link]() == submitButton) {

if (![Link]()) {

[Link](this, "Please agree to submit!",


"Warning", JOptionPane.WARNING_MESSAGE);

return;

String name = [Link]();

String gender = [Link]() ? "Male" :


([Link]() ? "Female" : "Not selected");

String feedback = [Link]();

// Show feedback in dialog box


[Link](this,

"Thank you for your feedback!\n\nName: " + name +

"\nGender: " + gender +

"\nFeedback: " + feedback,

"Submission Successful",

JOptionPane.INFORMATION_MESSAGE);

if ([Link]() == clearButton) {

[Link]("");

[Link]("");

[Link]();

[Link](false);

// Main method

public static void main(String[] args) {

new FeedbackForm();

}
OUTPUT:

You might also like