0% found this document useful (0 votes)
4 views1 page

Java Swing Comment Form Example

The document contains a Java program that creates a graphical user interface for a comment form using Swing. It includes fields for entering a name and comments, along with a submit button. The layout is managed using GridBagLayout to arrange the components effectively.

Uploaded by

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

Java Swing Comment Form Example

The document contains a Java program that creates a graphical user interface for a comment form using Swing. It includes fields for entering a name and comments, along with a submit button. The layout is managed using GridBagLayout to arrange the components effectively.

Uploaded by

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

Practical 21: Q4

import javax.swing.*;
import java.awt.*;
public class CommentForm extends JFrame
{
public CommentForm()
{
setTitle("Comment Form");
setSize(400, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridBagLayout());
JLabel nameLabel = new JLabel("Name");
JTextField nameField = new JTextField(20);
JLabel commentLabel = new JLabel("Comments");
JTextArea commentArea = new JTextArea(5, 20);
JScrollPane scrollPane = new JScrollPane(commentArea);
JButton submitButton = new JButton("Submit");
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.anchor = GridBagConstraints.WEST;
gbc.gridx = 0;
gbc.gridy = 0;
add(nameLabel, gbc);
gbc.gridx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
add(nameField, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
add(commentLabel, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridheight = 2;
gbc.fill = GridBagConstraints.BOTH;
add(scrollPane, gbc);
gbc.gridheight = 1;
gbc.gridx = 1;
gbc.gridy = 3;
gbc.anchor = GridBagConstraints.CENTER;
add(submitButton, gbc);
setVisible(true);
}
public static void main(String[] args)
{
new CommentForm();
}
}

You might also like