Java #52: GridLayout Example

//————–Output————————–


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

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

package dagbacomputers;

//Imports
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
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//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
frame.pack();
frame.setVisible(true);

}
//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:

WordPress.com Logo

You are commenting using your WordPress.com 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

Blog at WordPress.com.

Up ↑

%d bloggers like this: