Advertisement
fabioceep

JAVA: Layout de Fluxo 02 (PG 290)

Feb 22nd, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package gerenciadoreslayout;
  2. import javax.swing.*;
  3. import java.awt.*;
  4.  
  5. public class GerenciadoresLayout {
  6.     public static void main(String[] args) {
  7.         GerenciadoresLayout sistema = new GerenciadoresLayout();
  8.         sistema.iniciar();
  9.     }
  10.     public void iniciar() {
  11.         JFrame janela = new JFrame();
  12.         JPanel painel = new JPanel();
  13.        
  14.         painel.setBackground(Color.darkGray);
  15.        
  16.         /*
  17.         Altera o gerenciador(1) de layout para que seja uma nova instacia de
  18.         boxLayout
  19.         */
  20.        
  21.         painel.setLayout(new BoxLayout(painel, BoxLayout.Y_AXIS));
  22.         /*         ^1         ^2         ^3 */
  23.         /*
  24.         O construtor de BoxLayout(2) precisa conhecer o componente(3) que está
  25.         disposto isto é o painel, e que eixo
  26.         usar Y.AXIS = empilhamento vertical
  27.         */
  28.        
  29.         JButton east = new JButton("east");
  30.         JButton east1 = new JButton("east1");
  31.  
  32.         JButton west = new JButton("west");
  33.         JButton north = new JButton("Nort");
  34.         JButton south = new JButton("South");
  35.         JButton center = new JButton("Center");
  36.        
  37.         janela.getContentPane().add(BorderLayout.EAST, painel);
  38.         painel.add(east);
  39.         painel.add(east1);
  40.        
  41.         janela.getContentPane().add(BorderLayout.WEST, west);
  42.         janela.getContentPane().add(BorderLayout.NORTH, north);
  43.         janela.getContentPane().add(BorderLayout.SOUTH, south);
  44.         janela.getContentPane().add(BorderLayout.CENTER, center);
  45.        
  46.         janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47.         janela.setSize(200,200);
  48.         janela.setVisible(true);
  49.     }
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement