send
Grupo de Telegram
play_arrow
Este sitio utiliza cookies propias y de terceros. Si continúa navegando consideramos que acepta el uso de cookies. OK Más Información.

Interfaz Grafica en Java [Segunda parte]

  • 0 Respuestas
  • 2331 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Expermicid

  • *
  • Underc0der
  • Mensajes: 457
  • Actividad:
    0%
  • Reputación 0
  • _-Expermicid-_
    • Ver Perfil
  • Skype: expermicid.xd
« en: Marzo 17, 2013, 11:54:26 am »
Hola a todos. Hoy vamos a seguir con esta segunda parte, en donde vemos primeramente como se pueden organizar los objetos dentro de la ventana. Y si no se hace muy largo veremos tambien los eventos.

Que es un layout?

Es un objeto que determina la posicion de los componentes en una ventana o panel. Es decir, es el encargado de distribuir los espacios. Hay varios tipos de layout y hasta podemos crear nuevos.

Vamos a ver un conjunto de layout con sus caracteristicas.

Para empezar cree una ventana con las configuraciones comunes que vimos en la primera parte.

Código: Java
  1. import javax.swing.JFrame;
  2.  
  3. public class Windows  extends You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login  {
  4.        
  5.         Windows() {
  6.                 setTitle("Ventana con Componentes");
  7.                 setSize(300, 100);
  8.                 setVisible(true);
  9.                 setDefaultCloseOperation(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EXIT_ON_CLOSE);        
  10.         }
  11. }

Ahora en ese mismo contructor le vamos a agregar algunas lineas mas.

Creamos un Contenedor. En donde vamos a ir poniendo los diferentes componentes.

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login contenedor = getContentPane();

Pero para esto vamos a necesitar importar:

Código: Java
  1. import java.awt.Container;

Border Layout

Este es el que esta por defecto. Para agregar un componente hay que especificarle una de las siguiente posiciones: Norte, Este, Oeste, Sur o Centro.

Creamos algunos componentes:

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  2. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  3. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Label");
  4. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login check = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer CheckBox");
  5. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Button");

Y ahora vamos a agregarlos al Contenedor, es aqui donde le vamos a especificar la posicion:

Código: Java
  1. contenedor.add(label1, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.NORTH);
  2. contenedor.add(label2, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EAST);
  3. contenedor.add(button2, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.WEST);
  4. contenedor.add(button1, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.SOUTH);
  5. contenedor.add(check, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.CENTER);



Codigo completo del constructor:

Código: Java
  1. Windows() {
  2.         setTitle("Ventana con Componentes");
  3.         setSize(300, 100);
  4.         setVisible(true);
  5.         setDefaultCloseOperation(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EXIT_ON_CLOSE);
  6.                
  7.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login contenedor = getContentPane();
  8.                
  9.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  10.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  11.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Label");
  12.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login check = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer CheckBox");
  13.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Button");
  14.                
  15.         contenedor.add(label1, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.NORTH);
  16.         contenedor.add(label2, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EAST);
  17.         contenedor.add(button2, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.WEST);
  18.         contenedor.add(button1, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.SOUTH);
  19.         contenedor.add(check, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.CENTER);
  20. }

Box Layout

En este modo, los componentes intentan ocupar el menor espacion que puedan.

Para utilizarlo hay que crear un BoxLayout primero:

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login box = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(contenedor, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.Y_AXIS);

Estamos creando una instancia de un BoxLayout llamado box. Entre los parentesis van dos parametros, el primero es el contenedor al que le vamos a aplicar el layout y el segundo es la distribucion que van a tomar los componentes. En este caso es BoxLayout.Y_AXIS, donde se ordenan verticalmente, pero tambien podria haber sido BoxLayout.X_AXIS en donde se organizarian horizontalmente.

Ahora le decimos al contenedor que utilice ese layout:

Código: Java
  1. contenedor.setLayout(box);

Utilizando los mismo componente que en el caso anterior.

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  2. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  3. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Label");
  4. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login check = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer CheckBox");
  5. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Button");

Para terminar se los agregamos al contenedor:

Código: Java
  1. contenedor.add(label1);
  2. contenedor.add(button1);
  3. contenedor.add(label2);
  4. contenedor.add(check);
  5. contenedor.add(button2);

Y el resultado es:



Codigo completo del constructor:

Código: Java
  1. Windows() {
  2.         setTitle("Ventana con Componentes");
  3.         setSize(300, 100);
  4.         setVisible(true);
  5.         setDefaultCloseOperation(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EXIT_ON_CLOSE);
  6.                
  7.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login contenedor = getContentPane();
  8.                
  9.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login box = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(contenedor, You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.Y_AXIS);
  10.         contenedor.setLayout(box);
  11.                
  12.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  13.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  14.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Label");
  15.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login check = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer CheckBox");
  16.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Button");
  17.                
  18.         contenedor.add(label1);
  19.         contenedor.add(button1);
  20.         contenedor.add(label2);
  21.         contenedor.add(check);
  22.         contenedor.add(button2);
  23. }

Flow Layout

Este Layout va agregando los componentes en el espacio que tiene disponible.

Creamos la instancia del FlowLayout y se la asignamos al contenedor:
Pero primero vamos a necesitar importar:

Código: Java
  1. import java.awt.FlowLayout;

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login flow = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  2. contenedor.setLayout(flow);

Creamos los componentes y los agregamos al Conteiner:

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  2. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  3. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Label");
  4. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login check = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer CheckBox");
  5. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Button");
  6.                
  7. contenedor.add(label1);
  8. contenedor.add(button1);
  9. contenedor.add(label2);
  10. contenedor.add(check);
  11. contenedor.add(button2);

Obteniendo:



Codigo completo del constructor:

Código: Java
  1. Windows() {
  2.         setTitle("Ventana con Componentes");
  3.         setSize(300, 100);
  4.         setVisible(true);
  5.         setDefaultCloseOperation(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EXIT_ON_CLOSE);
  6.                
  7.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login contenedor = getContentPane();
  8.  
  9.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login flow = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  10.         contenedor.setLayout(flow);
  11.                
  12.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  13.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  14.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Label");
  15.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login check = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer CheckBox");
  16.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Button");
  17.  
  18.         contenedor.add(label1);
  19.         contenedor.add(button1);
  20.         contenedor.add(label2);
  21.         contenedor.add(check);
  22.         contenedor.add(button2);
  23. }

Grid Layout

En este caso los componentes se ordenan haciendo uso de tablas.

Instanciamos el GridLayout, en donde le pasamos como parametros las filas y columnas.
Y se lo asignamos al contenedor.

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login grid = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(3,2);
  2. contenedor.setLayout(grid);

En nuestro caso usaremos 3 filas y 2 columnas.
Ademas necesitamos importar:

Código: Java
  1. import java.awt.GridLayout;

Agregamos los componentes al contenedor.
Y nos quedara:



Codigo completo del constructor:

Código: Java
  1. Windows() {
  2.         setTitle("Ventana con Componentes");
  3.         setSize(300, 100);
  4.         setVisible(true);
  5.         setDefaultCloseOperation(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EXIT_ON_CLOSE);
  6.                
  7.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login contenedor = getContentPane();
  8.                
  9.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login grid = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(3,2);
  10.         contenedor.setLayout(grid);
  11.                
  12.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  13.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  14.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Label");
  15.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login check = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer CheckBox");
  16.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Segundo Button");
  17.                
  18.         contenedor.add(label1);
  19.         contenedor.add(button1);
  20.         contenedor.add(label2);
  21.         contenedor.add(check);
  22.         contenedor.add(button2);
  23. }

Paneles

Para finalizar vamos a ver como implementar paneles y que nos va a servir mucho tambien para la organizacion de los componentes dentro de la ventana.

Para comenzar vamos a crear una ventana comun como hemos hecho anteriormente. Al cual le agregaremos ya un Container.

Código: Java
  1. import java.awt.Container;
  2. import javax.swing.*;
  3.  
  4. public class Windows extends You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login {
  5.        
  6.         Windows() {
  7.                 setTitle("Ventana con Componentes");
  8.                 setSize(300, 300);
  9.                 setVisible(true);
  10.                 setDefaultCloseOperation(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EXIT_ON_CLOSE);
  11.                
  12.                 You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login contenedor = getContentPane();
  13.         }
  14. }

Ahora voy a crear una nueva clase llamada Panel que herede de JPanel. Y le agregare un Constructor en donde le cambio el color de fondo para que se note luego en la imagen.

Código: Java
  1. import java.awt.Color;
  2.  
  3. public class You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login extends You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login{    // Clase Panel heredada de JPanel
  4.        
  5.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(){    // Constructor
  6.                 setBackground(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.BLUE);    // Color de fondo
  7.         }
  8.  
  9. }

Volvemos al constructor de la ventana, creamos una instancia de la clase Panel y se la agregamos al contenedor.

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login panel = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();   // instanciamos un objeto Panel
  2. contenedor.add(panel);   // lo agregamos al contenedor



Si notamos en la imagen vemos al panel por el color de fondo Azul que ocupa todo la ventana.

Y podemos agregarle componentes al Panel desde su contructor.

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Label");
  2. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Primer Button");
  3.                
  4. add(label);
  5. add(button);



Ahora ustedes se preguntaran, para que hacer todo esto de crear un Panel si podemos agregar los componentes en el mismo contenedor.

La ventanja es que por ejemplo en el contenedor de la ventana podemos ponerle un Layout Grid y en lo que seria cada celda ponerle un panel distinto.

Vamos a crear una ventana en donde le agregaremos un contenedor con un GridLayout de 3 filas y 1 columna.

Contructor:

Código: Java
  1. Windows() {
  2.         setTitle("Ventana con Componentes");
  3.         setSize(300, 300);
  4.         setVisible(true);
  5.         setDefaultCloseOperation(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.EXIT_ON_CLOSE);
  6.        
  7.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login contenedor = getContentPane();        // contenedor de la ventana
  8.         You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login grid = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(3,1);   // instanciamos un objeto GridLayout
  9.         contenedor.setLayout(grid);       // se lo agregamos al contenedor
  10. }

Y vamos a crea dos clases:

Una para un panel llamada PanelUno que herede de JPanel y cuyo color de fondo va a ser Cyan.

Código: Java
  1. import java.awt.Color;
  2. import javax.swing.JPanel;
  3.  
  4. public class PanelUno extends You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login{
  5.        
  6.         PanelUno() {
  7.                 setBackground(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.CYAN);
  8.         }
  9. }

La segunda clase para otro panel llamada PanelDos que herede de JPanel y cuyo color de fondo sea Green.

Código: Java
  1. import java.awt.Color;
  2. import javax.swing.JPanel;
  3.  
  4. public class PanelDos extends You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login{
  5.        
  6.         PanelDos() {
  7.                 setBackground(You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login.GREEN);
  8.         }
  9.        
  10. }

Volvemos al constructor de la ventana y le agregamos los dos paneles al Layout.

Código: Java
  1. PanelUno panel1 = new PanelUno();       // instanciamos un objeto de PanelUno
  2. PanelDos panel2 = new PanelDos();       // instanciamos un objeto de PanelDos
  3.                
  4. // agregamos los paneles al contenedor
  5. contenedor.add(panel1);
  6. contenedor.add(panel2);



Mirando los colores podemos apreciar la ubicacion de cada panel. Y hay una tercer celda en donde no esta en uso.

Y como un Panel es un como un contendor, le podemos asignar un Layout.

Al PanelUno le vamos a poner un GridLayout.

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login grid = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login(2,2);
  2. setLayout(grid);[//CODE]
  3.  
  4. Al [B]PanelDos[/B] le vamos a poner un [B]You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login[/B].
  5.  
  6. [CODE=java]You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login flow = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login();
  7. setLayout(flow);

Para terminar la demostracion le agregamos unos componentes para ver la diferenciacion.

Código: Java
  1. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Label1");
  2. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login label2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Label2");
  3. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button1 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Button1");
  4. You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login button2 = new You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login("Button2");
  5.                
  6. add(label1);
  7. add(label2);
  8. add(button1);
  9. add(button2);

Quedandonos:



Como podran ver la organizacion de los componentes es distintas gracias a poder ponerle un layout distinto a cada panel.

:) Bueno espero que les sirva.

Saludos
« Última modificación: Marzo 17, 2013, 11:56:34 am por Expermicid »

 

¿Te gustó el post? COMPARTILO!



[Video Curso] Iniciacion a Java por DesarrolloWeb y EscuelaIT Mayo 2014

Iniciado por graphixx

Respuestas: 3
Vistas: 1396
Último mensaje Febrero 23, 2015, 10:13:28 am
por Hu3c0
Como compilar programas Java en la consola de comandos de Windows

Iniciado por tar3kw0rm3d

Respuestas: 2
Vistas: 2098
Último mensaje Junio 04, 2013, 02:55:07 pm
por tar3kw0rm3d
Java Extremo [Video Cursos Completos] [Español] [ISO] 2009

Iniciado por graphixx

Respuestas: 9
Vistas: 4170
Último mensaje Diciembre 04, 2017, 02:36:34 am
por graphixx
[LIBRO] Programación avanzada en Java - Sonia Jaramillo Valbuena

Iniciado por graphixx

Respuestas: 1
Vistas: 2328
Último mensaje Noviembre 07, 2017, 12:34:40 pm
por K0m0dr3x
Tutorial: Traduccion de aplicaciones JAVA - Moviles [By :: SmartGenius :: ]

Iniciado por ProcessKill

Respuestas: 0
Vistas: 1454
Último mensaje Febrero 24, 2010, 04:26:07 pm
por ProcessKill