Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Layout extends JFrame {
- private JButton lb, cb, rb;
- private FlowLayout layout;
- private Container container;
- public Layout() {
- super("The title");
- layout = new FlowLayout();
- container = getContentPane();
- setLayout(layout);
- lb = setAllLayouts(lb, "Left");
- cb = setAllLayouts(cb, "Center");
- rb = setAllLayouts(rb, "Right");
- }
- public JButton setAllLayouts(JButton bb, String s) {
- bb = new JButton(s);
- this.add(bb);
- bb.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- if (event.getSource() == lb)
- layout.setAlignment(FlowLayout.LEFT);
- else if (event.getSource() == cb)
- layout.setAlignment(FlowLayout.CENTER);
- else if (event.getSource() == rb)
- layout.setAlignment(FlowLayout.RIGHT);
- layout.layoutContainer(container);
- }
- });
- return bb;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement