miércoles, 27 de mayo de 2009

Ejercicio Panel




import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class DemoPanel extends JFrame{
Container contenedor;
private JPanel panelInicio;
private JPanel panelFin;
private JButton[][]botones;
private JLabel [][]texto;
private JPanel panelInterD;
private JTextField [][] text;
private JPanel panelInterI;


public DemoPanel(){
super("MI PANEL");
botones= new JButton[2][2];
contenedor = getContentPane();
panelInicio = new JPanel(new GridLayout(2,2));
String [] nombres ={"Enero", "Febrero", "Marzo", "Abril"};

int k =0;
for(int i = 0; i<2; i++){
for(int j = 0; j<2; j++){
botones[i][j] = new JButton(nombres[k]);
k += 1;
panelInicio.add(botones[i][j]);

}
}
contenedor.add(panelInicio,BorderLayout.NORTH);

texto = new JLabel[5][5];
panelFin = new JPanel (new GridLayout(5,5,10,10));
for(int i = 0; i<5; i++){
for(int j = 0; j<5; j++){
texto[i][j]= new JLabel("texto"+i+" "+j);
panelFin.add(texto[i][j]);
}
}
contenedor.add(panelFin, BorderLayout.SOUTH);


text = new JTextField[4][3];
panelInterD = new JPanel (new GridLayout(5,5,10,10));
for(int i = 0; i<4; i++){
for(int j = 0; j<3; j++){
text[i][j]= new JTextField("texto"+i+" "+j);
panelInterD.add(text[i][j]);
}
}
contenedor.add(panelInterD, BorderLayout.WEST);

text = new JTextField [2][4];
panelInterI = new JPanel (new GridLayout(5,5,10,10));
for(int i = 0; i<2; i++){
for(int j = 0; j<4; j++){
text[i][j]= new JTextField("texto"+i+" "+j);
panelInterI.add(text[i][j]);
}
}
contenedor.add(panelInterI, BorderLayout.EAST);

setSize(425,150);
setVisible(true);
}

public static void main(String args[]){
DemoPanel aplicacion = new DemoPanel();
aplicacion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

4 comentarios:

  1. Los paneles que haces esta bien estructurado...
    Es interesante como haces grandes los textos

    ResponderEliminar
  2. muy buen trabajo.... se muestra practicamente como hacer un panel y los pasos que se emplea para llevarlo a cabo....

    ResponderEliminar
  3. Encuentro muy bien el panel, podrias implementarle un poco mas de filas y columnas en los labels.

    ResponderEliminar
  4. Tu panel esta bien hecho muy simetrico

    ResponderEliminar