import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.Container;
import java.awt.BorderLayout;
public class MyBorder4 extends JFrame // always has 2 parts
{
//--------------------------------------------------------------------------
// data members - these are instances of the button class
//--------------------------------------------------------------------------
JButton n = new JButton("Minnesota" );
JButton s = new JButton("Georgia" );
JButton e = new JButton("Virginia" );
JButton w = new JButton("Oregon" );
JButton c = new JButton("Kansas" );
//--------------------------------------------------------------------------
// method members
//--------------------------------------------------------------------------
// Default constructor : 3 steps
public MyBorder4()
{
// 1. Create a canvas (named c1)
Container c1 = getContentPane();
// 2. Set layout with 5 regions with horizontal gap 5
// and vertical 10
c1.setLayout(new BorderLayout(5,10));
// 3. place button objects on canvas
c1.add(e, BorderLayout.EAST );
c1.add(w, BorderLayout.WEST );
c1.add(s, BorderLayout.SOUTH );
c1.add(n, BorderLayout.NORTH );
c1.add(c, BorderLayout.CENTER);
}
//----------------------------------------------------------------------------------
// Main method
//----------------------------------------------------------------------------------
public static void main(String[] args)
{
MyBorder4 frame1 = new MyBorder4();
frame1.setTitle("Lynn Tobias' Border Layout");
frame1.setDefaultCloseOperation(3);
frame1.setSize(300,150);
frame1.setVisible(true);
}
}