import java.awt.*; import javax.swing.*; class JSimpleGUI1 extends JFrame { private JLabel label; private JTextField tf; private JButton okB, exitB; public JSimpleGUI1() { // create the atomic components label = new JLabel("Enter your name"); tf = new JTextField(20); okB = new JButton("Ok"); exitB = new JButton("Exit"); // create the intermediate containers JPanel pane1 = new JPanel(); // default flow layout pane1.add(label); JPanel pane2 = new JPanel(); // default flow layout pane2.add(tf); pane2.add(okB); JPanel pane3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // flow layout with alignment to the right pane3.add(exitB); //set layout for the whole frame and add intermediate containers this.getContentPane().setLayout(new GridLayout(0,1)); this.getContentPane().add(pane1); this.getContentPane().add(pane2); this.getContentPane().add(pane3); } // end constructor public static void main(String[] args) { JSimpleGUI1 window = new JSimpleGUI1(); window.setTitle("SimpleGUI"); window.pack(); window.setVisible(true); } }