Java #52: GridLayout Example


//————Full Source Code——————

//Programmer:Akinwale Owi
//Company: Dagba Computers
//Program Purpose: GridLayout Example using JRadioButtons

package dagbacomputers;

import java.awt.GridLayout;
import javax.swing.JRadioButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.*;

//Beginning of DagbaComputers (Class containing the Main function)
public class DagbaComputers
//Main Function
public static void main(String[] args)
//Creating the JFrame
JFrame frame = new JFrame(“Dagba Computers GridLayout Example”);

//Setting close operation

//Size of JFrame
frame.setPreferredSize(new Dimension (400, 400));

//The Dimensions of the Grid (rows, columns)
frame.setLayout(new GridLayout(2, 2));

//Adding items to the Grid
frame.add(new JRadioButton(“Spot 1”));
frame.add(new JRadioButton(“Spot 2”));
frame.add(new JRadioButton(“Spot 3”));
frame.add(new JRadioButton (“Spot 4”));
frame.add(new JLabel(“”));//I used this to create a space because
frame.add(new JRadioButton(“Spot 6”));

//Pack and Visibility

//End of Main Function

//End of DagbaComputers Class

//————-End of the Program—————–

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s