Java

                Never    
Java
       
import javax.swing.*;
import java.awt.*;
import java.awt.GridLayout;

class Ch14GridLayoutSample extends JFrame {
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 200;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
//---------------------------------// Main method
public static void main(String[]args){

Ch14GridLayoutSample frame = new Ch14GridLayoutSample();
frame.setVisible(true);
}
public Ch14GridLayoutSample() {
Container contentPane;
JButton button1, button2, button3, button4, button5;
//set the frame properties
setSize  (FRAME_WIDTH, FRAME_HEIGHT);
setTitle  ("Program Ch14GridLayoutSample");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
contentPane = getContentPane( );
contentPane.setBackground( Color.WHITE );
contentPane.setLayout(new GridLayout(2,3));
//create and place four buttons on the content pane
button1 = new JButton("button 1");
button2 = new JButton("button 2");
button3 = new JButton("button 3");
button4 = new JButton("button 4");
button5 = new JButton("button 5");
contentPane.add(button1);
contentPane.add(button2);
contentPane.add(button3);
contentPane.add(button4);
contentPane.add(button5);
//register 'Exit upon closing' as a default close operation
setDefaultCloseOperation(EXIT_ON_CLOSE );
}
}


import javax.swing.*;
import java.awt.*;
import java.awt.BorderLayout;

class Ch14BorderLayoutSample extends JFrame {
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 200;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
public static void main(String[]args){
Ch14BorderLayoutSample frame = new Ch14BorderLayoutSample();
frame.setVisible(true);
}
public Ch14BorderLayoutSample() {
Container contentPane;
JButton button1, button2, button3, button4, button5;
//set the frame properties
setSize  (FRAME_WIDTH, FRAME_HEIGHT);
setTitle  ("Program Ch14BorderLayoutSample");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
contentPane = getContentPane( );
contentPane.setBackground(Color.WHITE);
contentPane.setLayout(new BorderLayout());
//contentPane.setLayout(new BorderLayout(/*hgap*/10, /*vgap*/10));
//create and place four buttons on the content pane
button1 = new JButton("button 1");
button2 = new JButton("button 2");
button3 = new JButton("button 3");
button4 = new JButton("button 4");
button5 = new JButton("button 5");
contentPane.add(button1, BorderLayout.NORTH);
contentPane.add(button2, BorderLayout.SOUTH);
contentPane.add(button3, BorderLayout.EAST);
contentPane.add(button4, BorderLayout.WEST);
contentPane.add(button5, BorderLayout.CENTER);
//register 'Exit upon closing' as a default close operation
setDefaultCloseOperation( EXIT_ON_CLOSE );
}
}

Raw Text