Advertisement
apl-mhd

LaoutContainer

Dec 17th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. public class FlowLaout extends JFrame {
  9.  
  10.  
  11.     private  final JButton leftButton;
  12.     private  final JButton centerButton;
  13.     private  final JButton rightButton;
  14.  
  15.     private final FlowLayout layout;
  16.     private final Container container;
  17.  
  18.  
  19.     public FlowLaout(){
  20.         super("This is flow layout");
  21.         layout = new FlowLayout();
  22.         container = getContentPane();
  23.  
  24.         setLayout(layout);
  25.  
  26.         leftButton = new JButton("Left");
  27.         add(leftButton);
  28.         leftButton.addActionListener(new ActionListener() {
  29.             @Override
  30.             public void actionPerformed(ActionEvent e) {
  31.                 layout.setAlignment(FlowLayout.LEFT);
  32.                 layout.layoutContainer(container);
  33.             }
  34.         });
  35.  
  36.  
  37.         centerButton = new JButton("Center");
  38.         add(centerButton);
  39.         centerButton.addActionListener(new ActionListener() {
  40.             @Override
  41.             public void actionPerformed(ActionEvent e) {
  42.                 layout.setAlignment(FlowLayout.CENTER);
  43.                 layout.layoutContainer(container);
  44.             }
  45.         });
  46.  
  47.  
  48.  
  49.         rightButton = new JButton("Right");
  50.         add(rightButton);
  51.         rightButton.addActionListener(new ActionListener() {
  52.             @Override
  53.             public void actionPerformed(ActionEvent e) {
  54.                 layout.setAlignment(FlowLayout.RIGHT);
  55.                 layout.layoutContainer(container);
  56.             }
  57.         });
  58.  
  59.  
  60.  
  61.  
  62.  
  63.     }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.     public static void main(String[] args) {
  73.     // write your code here
  74.  
  75.  
  76.         FlowLaout flowLaout = new FlowLaout();
  77.  
  78.  
  79.         flowLaout.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  80.         flowLaout.setSize(300,75);
  81.         flowLaout.setVisible(true);
  82.  
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement