Lá vai o código:
import java.awt.<em>;
import javax.swing.</em>;
import java.awt.event.*;
public class GeraForm extends javax.swing.JFrame{
public JLabel lbls[];
public JTextField[] txts;
public GeraForm(String aTituloJanela,
int largJanela,
int altJanela ) {
super("Nome da janela Default");
setTitle(aTituloJanela);
setSize(largJanela, altJanela);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void GeraObjeto(Object [] [] aObjetos , int qtdObjetos, int tamTextField,
String conteudoLabel) {
System.out.print(aObjetos[0][0]);
System.out.print(aObjetos[0][1]);
System.out.print(aObjetos[1][0]);
System.out.print(aObjetos[1][1]);
System.out.print(aObjetos[2][0]);
System.out.print(aObjetos[2][1]);
GridBagLayout layoutTipoGrid = new GridBagLayout();
GridBagConstraints restricoesLayout = new GridBagConstraints();
JPanel painel1 = new JPanel();
Restricoes minhaRestricao = new Restricoes();
painel1.setLayout(layoutTipoGrid);
// Arrray de Textos
JLabel lbls[] = new JLabel[ qtdObjetos ];
JTextField txts[] = new JTextField[ qtdObjetos ];
for ( int i = 0; i < txts.length; i++ ) {
//lbls[ i ] = new JLabel(String() aObjetos[i][0]);
//lbls[ i ] = new JLabel("label__");
lbls[ i ] = new JLabel();
lbls[ i ].setText((String)aObjetos[i][0]);
minhaRestricao.criaRestricoes(restricoesLayout, 0, i,1,1,100,100,2,17);
layoutTipoGrid.setConstraints(lbls[i],restricoesLayout);
}
// ===================================
for ( int i = 0; i < txts.length; i++ ) {
txts[ i ] = new JTextField((Integer)aObjetos[i][1] );
// txts[ i ] = new JTextField(15);
minhaRestricao.criaRestricoes(restricoesLayout, 1,i,1,1,100,100,2,17);
layoutTipoGrid.setConstraints(txts[i],restricoesLayout); }
for ( int i = 0; i < txts.length; i++ ) {
painel1.add(txts[i]);
painel1.add(lbls[i]); }
setContentPane(painel1);
show();
}
public static void main(String[] arguments) {
Object [][] aObjetos = {{ "Nome" , "25" },
{ "Endereco", "40" },
{ "Fone" , "8" } };
// aObjetos[0] [0] = “Nome”;
// aObjetos[0] [1] = “25”;
// aObjetos[1] [0] = “Endereço”;
// aObjetos[1] [1] = “40”;
// aObjetos[2] [0] = “Fone”;
// aObjetos[2] [1] = “8”;
System.out.print(aObjetos[0][0]);
System.out.print(aObjetos[0][1]);
System.out.print(aObjetos[1][0]);
System.out.print(aObjetos[1][1]);
System.out.print(aObjetos[2][0]);
System.out.print(aObjetos[2][1]);
GeraForm tela = new GeraForm("minha tela",500, 175);
tela.GeraObjeto(aObjetos, 3,15,"meu label");
}
}