Advertisement
Guest User

Layout.java

a guest
Nov 18th, 2013
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Layout extends JFrame {
  6.  
  7. private JButton lb, cb, rb;
  8. private FlowLayout layout;
  9. private Container container;
  10.  
  11. public Layout() {
  12. super("The title");
  13. layout = new FlowLayout();
  14. container = getContentPane();
  15. setLayout(layout);
  16.  
  17. lb = setAllLayouts(lb, "Left");
  18. cb = setAllLayouts(cb, "Center");
  19. rb = setAllLayouts(rb, "Right");
  20. }
  21.  
  22. public JButton setAllLayouts(JButton bb, String s) {
  23. bb = new JButton(s);
  24. this.add(bb);
  25. bb.addActionListener(new ActionListener() {
  26. public void actionPerformed(ActionEvent event) {
  27. if (event.getSource() == lb)
  28. layout.setAlignment(FlowLayout.LEFT);
  29.  
  30. else if (event.getSource() == cb)
  31. layout.setAlignment(FlowLayout.CENTER);
  32.  
  33. else if (event.getSource() == rb)
  34. layout.setAlignment(FlowLayout.RIGHT);
  35.  
  36. layout.layoutContainer(container);
  37. }
  38. });
  39. return bb;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement