Guest User

Untitled

a guest
Oct 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class SampleLayout
  5. {
  6. private JFrame f;
  7. private JButton[] b;
  8.  
  9. public SampleLayout()
  10. {
  11. f = new JFrame("Sample Layout");
  12. String[] loc = {"North","South","East","West","Center"};
  13. b = new JButton[5];
  14. for(int i = 0; i<b.length; i++)
  15. {
  16. b[i] = new JButton(loc[i]);
  17. }
  18. }
  19.  
  20. public void launch()
  21. {
  22. f.setLayout(new BorderLayout());
  23. f.add(b[0],BorderLayout.NORTH);
  24. f.add(b[1],BorderLayout.SOUTH);
  25. f.add(b[2],BorderLayout.EAST);
  26. f.add(b[3],BorderLayout.WEST);
  27. f.add(b[4],BorderLayout.CENTER);
  28. f.setVisible(true);
  29. f.setBounds(10,10,500,500);
  30. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31. }
  32. }
Add Comment
Please, Sign In to add comment