java Practical 21
java Practical 21
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();
}
}