Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- public class SampleLayout
- {
- private JFrame f;
- private JButton[] b;
- public SampleLayout()
- {
- f = new JFrame("Sample Layout");
- String[] loc = {"North","South","East","West","Center"};
- b = new JButton[5];
- for(int i = 0; i<b.length; i++)
- {
- b[i] = new JButton(loc[i]);
- }
- }
- public void launch()
- {
- f.setLayout(new BorderLayout());
- f.add(b[0],BorderLayout.NORTH);
- f.add(b[1],BorderLayout.SOUTH);
- f.add(b[2],BorderLayout.EAST);
- f.add(b[3],BorderLayout.WEST);
- f.add(b[4],BorderLayout.CENTER);
- f.setVisible(true);
- f.setBounds(10,10,500,500);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Add Comment
Please, Sign In to add comment