Advertisement
zoro-10

DemoBorderLayout.java

Mar 30th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class DemoBorderLayout {
  5.  
  6.   public static void main(String args[]) {
  7.     JFrame frame = new JFrame("Border Layout");
  8.     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  9.     frame.setSize(300, 200);
  10.     JButton northButton = new JButton("North");
  11.     JButton southButton = new JButton("South");
  12.     JButton eastButton = new JButton("East");
  13.     JButton westButton = new JButton("West");
  14.     JButton centerButton = new JButton("Center");
  15.     Container contentPane = frame.getContentPane();
  16.     contentPane.setLayout(new BorderLayout());
  17.     contentPane.add(northButton, BorderLayout.NORTH);
  18.     contentPane.add(southButton, BorderLayout.SOUTH);
  19.     contentPane.add(eastButton, BorderLayout.EAST);
  20.     contentPane.add(westButton, BorderLayout.WEST);
  21.     contentPane.add(centerButton, BorderLayout.CENTER);
  22.     frame.setVisible(true);
  23.   }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement