0% found this document useful (0 votes)
3 views2 pages

Practical 4

Uploaded by

tidew88312
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)
3 views2 pages

Practical 4

Uploaded by

tidew88312
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
You are on page 1/ 2

import javax.swing.

*;

import java.awt.*;

public class GridBagdemo{

public static void main(String[] args) {

JFrame frame = new JFrame("GridBagLayout Demo");

frame.setLayout(new GridBagLayout());

GridBagConstraints gbc = new GridBagConstraints();

JLabel nameLabel = new JLabel("Name:");

gbc.gridx = 0;

gbc.gridy = 0;

frame.add(nameLabel, gbc);

JTextField nameField = new JTextField(15);

gbc.gridx = 1;

gbc.gridy = 0;

gbc.gridwidth = 2;

frame.add(nameField, gbc);

JLabel addressLabel = new JLabel("Address:");

gbc.gridx = 0;

gbc.gridy = 1;

frame.add(addressLabel, gbc);

JTextArea addressArea = new JTextArea(5, 15);

gbc.gridx = 1;

gbc.gridy = 1;

gbc.gridwidth = 2;

frame.add(new JScrollPane(addressArea), gbc);

JButton submitButton = new JButton("Submit");

gbc.gridx = 1;

gbc.gridy = 2;

frame.add(submitButton, gbc);

frame.setSize(350, 250);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

You might also like