miércoles, 27 de mayo de 2009

PANELES


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 panelcampo;
private JPanel panelcampo1;
private JTextField[][] campo;
private JTextField[][] campo1;

public DemoPanel(){
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++){
//for(int i=0; i //for(int j=0; j<3; j++){
//botones[i][j]= new JButton("boton"+i+" "+j);
botones[i][j]= new JButton(nombres [k]);
k +=1;
panelinicio.add(botones[i][j]);
}
}
contenedor.add(panelinicio,BorderLayout.NORTH);
setSize(425,150);
setVisible(true);
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);
}
campo= new JTextField[4][3];
panelcampo= new JPanel(new GridLayout(4,3,5,5));
for(int i=0; i<4; i++){
for(int j=0; j<3; j++){
campo[i][j]= new JTextField("campo"+i+" "+j);
panelcampo.add(campo[i][j]);

}
contenedor.add(panelcampo,BorderLayout.WEST);
}
campo1= new JTextField[2][4];
panelcampo1= new JPanel(new GridLayout(4,2,5,5));
for(int i=0; i<2; i++){
for(int j=0; j<4; j++){
campo1[i][j]= new JTextField("campo1"+i+" "+j);
panelcampo1.add(campo1[i][j]);

}
contenedor.add(panelcampo1,BorderLayout.EAST);
}
}

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

}

4 comentarios:

  1. EL CODIGO ESTA MUY BIEN SIMPIFICADO, Y GRAFICA DE MANERA PRECISA Y CORRECTA LA DISTRIBUCION PEDIDA EN CLASE. BUEN TRABAJO.

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

    ResponderEliminar
  3. el codigo de los paneles esta muy claro... las funciones se las entiende perfectamente.. felicitaciones

    ResponderEliminar
  4. muy buen trabajo, el codigo es bastante claro,
    creo que las funciones estan bien empleadas, felicitaciones.

    ResponderEliminar