Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package botonesappletgridlayout;
  2.  
  3. import java.awt.Color;
  4. import java.awt.GridBagLayout;
  5. import java.awt.GridLayout;
  6. import javax.swing.JApplet;
  7. import javax.swing.JButton;
  8.  
  9. /**
  10.  *
  11.  * @author Rafa
  12.  */
  13. public class BotonesAppletGridLayout extends JApplet{
  14.     //declaramos los botones
  15.     private JButton boton1;
  16.     private JButton boton2;
  17.     private JButton boton3;
  18.     private JButton boton4;
  19.  
  20.     public void init(){
  21.         //establece tipo de composicion y tamano de matriz(2-2)
  22.         setLayout(new GridLayout(2,2));
  23.        
  24.         //creamos los botones
  25.         boton1 = new JButton("Boton1");
  26.         boton2 = new JButton("Boton2");
  27.         boton3 = new JButton("Boton3");
  28.         boton4 = new JButton("Boton4");
  29.        
  30.         //Establecemos colores
  31.         boton1.setBackground(Color.green);
  32.         boton2.setBackground(Color.yellow);
  33.         boton3.setBackground(Color.red);
  34.         boton4.setBackground(Color.black);
  35.        
  36.         //Agregamos los botones
  37.         add(boton1);
  38.         add(boton2);
  39.         add(boton3);
  40.         add(boton4);
  41.     }
  42. }