Acceso a arreglos de componentes en arreglos de paneles en tabbedpane

Chrisitan Thowinsson
13 de Mayo del 2006
El siguiente codigo crea un arreglo 2d de TextFields para cada elemento del arreglo de paneles dinámicamente con datos de entrada en un evento de boton, quisiera saber como puedo acceder desde el action listener u otra rutina en la clase a los textos (getText por defecto) de cada elemento del arreglo de TextFields o al Valor de los JComboBoxes a través del panel contenedor de dicho arreglo o de cualquier otra forma para cargar esos valores a una matriz int o float y luego trabajarla....
Algo como

int M[i][j] = vbles[][].getText()? ó
int M[i][j] = paneles[].vbles[][].getText()? ò
paneles[].getComponent(1).getAccesibleContext(). etc---

no se cómo necesito ayuda urgente....!!!


import java.awt.*;
import java.awt.event.*;

/**
* Sample application using Frame.
*
* @author
* @version 1.00 06/05/09
*/
import java.awt.*;
import javax.swing.*;

class TabbedPane
extends JFrame implements ActionListener
{
private JTabbedPane tabbedPane;
private JPanel paneles[];
private int x,y;
private JTextField nvbles0, necua0, nvbles1, necua1, nvbles2, necua2;
private Container contentPane;

public TabbedPane()
{
setTitle( "Simplex" );
setSize( 500, 400 );
setBackground( Color.white );

//x = y = 3;
paneles = new JPanel[3];
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );

// Crear los tabs
creaPaginas();

// Crear un Tabbed Penel
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "Simplex", paneles[0] );
tabbedPane.addTab( "Simplex Tabular", paneles[1] );
tabbedPane.addTab( "Simplex Revisado", paneles[2] );
topPanel.add( tabbedPane, BorderLayout.CENTER );

/*
Container contentPane = getContentPane();
contentPane.add(paneles[0]);
contentPane.add(paneles[1]);
contentPane.add(paneles[2]);
*/

}

public void creaPaginas()
{


paneles[0] = new JPanel();
paneles[0].setLayout( null );

//Tab 0

JLabel label10 = new JLabel( "No.Variables:" );
label10.setBounds( 10, 15, 150, 20 );
paneles[0].add( label10 );

nvbles0 = new JTextField();
nvbles0.setBounds( 10, 35, 150, 20 );
nvbles0.addActionListener(this);
paneles[0].add(nvbles0,0);


JLabel label20 = new JLabel( "No. Ecuaciones:" );
label20.setBounds( 10, 60, 150, 20 );
paneles[0].add( label20 );

necua0 = new JTextField();
necua0.setBounds( 10, 80, 150, 20 );
necua0.addActionListener(this);
paneles[0].add(necua0,1);


JButton simplex = new JButton( "Simplex" );
simplex.setBounds(200,45,80,30);
simplex.addActionListener(this);
paneles[0].add( simplex );

//Fin Tab 0




paneles[1] = new JPanel();
paneles[1].setLayout( null );

//Tab 1

JLabel label11 = new JLabel( "No.Variables:" );
label11.setBounds( 10, 15, 150, 20 );
paneles[1].add( label11 );

nvbles1 = new JTextField();
nvbles1.setBounds( 10, 35, 150, 20 );
nvbles1.addActionListener(this);
paneles[1].add(nvbles1,0);


JLabel label21 = new JLabel( "No. Ecuaciones:" );
label21.setBounds( 10, 60, 150, 20 );
paneles[1].add( label21 );

necua1 = new JTextField();
necua1.setBounds( 10, 80, 150, 20 );
necua1.addActionListener(this);
paneles[1].add(necua1,1);

JButton simplextab = new JButton( "Simplex Tabular" );
simplextab.setBounds(200,45,180,30);
simplextab.addActionListener(this);
paneles[1].add( simplextab );

//Fin Tab 1




paneles[2] = new JPanel();
paneles[2].setLayout( null );

//Tab 2

JLabel label12 = new JLabel( "No.Variables:" );
label12.setBounds( 10, 15, 150, 20 );
paneles[2].add( label12 );

nvbles2 = new JTextField();
nvbles2.setBounds( 10, 35, 150, 20 );
nvbles2.addActionListener(this);
paneles[2].add(nvbles2,0); //Componente No. 0


JLabel label22 = new JLabel( "No. Ecuaciones:" );
label22.setBounds( 10, 60, 150, 20 );
paneles[2].add( label22 );

necua2 = new JTextField();
necua2.setBounds( 10, 80, 150, 20 );
necua2.addActionListener(this);
paneles[2].add(necua2,1); //Componente No. 1

JButton simplexrev = new JButton( "Simplex Revisado" );
simplexrev.setBounds(200,45,180,30);
simplexrev.addActionListener(this);
paneles[2].add( simplexrev );

//Fin Tab 2
}


public void botonera0(int x, int y){
Label vbles0[] = new Label [x];
TextField coef0[][] = new TextField [y][x];
JComboBox simb0[] = new JComboBox[y];
String simb[] = {"<=","="};

int a = 10, b = 150, ascii = 65;
String aChar;
for (int i = 0; i < y; i++){

for (int j = 0; j < x; j++){

if (j < x-1){
coef0[i][j] = new TextField();
coef0[i][j].setBounds(a+=50,b,40,20);
coef0[i][j].addActionListener(this);
paneles[0].add(coef0[i][j]);
}else{
if(i > 0){
simb0[i] = new JComboBox( simb );
simb0[i].setMaximumRowCount( 2 );
simb0[i].setBounds(a+=50,b,40,20);
simb0[i].addActionListener(this);
paneles[0].add(simb0[i]);

coef0[i][j] = new TextField();
coef0[i][j].setBounds(a+50,b,40,20);
coef0[i][j].addActionListener(this);
paneles[0].add(coef0[i][j]);
}
}

if(i < 1) {
if (j < x-1){
vbles0[j] = new Label(aChar = new Character((char)ascii++).toString());
vbles0[j].setBounds(a+10,b+25,40,20);
paneles[0].add(vbles0[j]);
}else{
vbles0[j] = new Label("Sol");
vbles0[j].setBounds(a+110,b+25,40,20);
paneles[0].add(vbles0[j]);
}
}

}
if(i == 0)
b+=50;
else
b+=25;

a = 10;
}

}



public void botonera1(int x, int y){
Label vbles1[] = new Label [x];
TextField coef1[][] = new TextField [y][x];
JComboBox simb1[] = new JComboBox[y];
String simb[] = {"<=","="};

int a = 10, b = 150, ascii = 65;
String aChar;
for (int i = 0; i < y; i++){

for (int j = 0; j < x; j++){

if (j < x-1){
coef1[i][j] = new TextField();
coef1[i][j].setBounds(a+=50,b,40,20);
coef1[i][j].addActionListener(this);
paneles[1].add(coef1[i][j]);
}else{
if(i > 0){
simb1[i] = new JComboBox( simb );
simb1[i].setMaximumRowCount( 2 );
simb1[i].setBounds(a+=50,b,40,20);
simb1[i].addActionListener(this);
paneles[1].add(simb1[i]);

coef1[i][j] = new TextField();
coef1[i][j].setBounds(a+50,b,40,20);
coef1[i][j].addActionListener(this);
paneles[1].add(coef1[i][j]);
}
}

if(i < 1) {
if (j < x-1){
vbles1[j] = new Label(aChar = new Character((char)ascii++).toString());
vbles1[j].setBounds(a+10,b+25,40,20);
paneles[1].add(vbles1[j]);
}else{
vbles1[j] = new Label("Sol");
vbles1[j].setBounds(a+110,b+25,40,20);
paneles[1].add(vbles1[j]);
}
}

}
if(i == 0)
b+=50;
else
b+=25;

a = 10;
}

}



public void botonera2(int x, int y){
Label vbles2[] = new Label [x];
TextField coef2[][] = new TextField [y][x];
JComboBox simb2[] = new JComboBox[y];
String simb[] = {"<=","="};

int a = 10, b = 150, ascii = 65;
String aChar;
for (int i = 0; i < y; i++){

for (int j = 0; j < x; j++){

if (j < x-1){
coef2[i][j] = new TextField();
coef2[i][j].setBounds(a+=50,b,40,20);
coef2[i][j].addActionListener(this);
paneles[2].add(coef2[i][j]);
}else{
if(i > 0){
simb2[i] = new JComboBox( simb );
simb2[i].setMaximumRowCount( 2 );
simb2[i].setBounds(a+=50,b,40,20);
simb2[i].addActionListener(this);
paneles[2].add(simb2[i]);

coef2[i][j] = new TextField();
coef2[i][j].setBounds(a+50,b,40,20);
coef2[i][j].addActionListener(this);
paneles[2].add(coef2[i][j]);
}
}

if(i < 1) {
if (j < x-1){
vbles2[j] = new Label(aChar = new Character((char)ascii++).toString());
vbles2[j].setBounds(a+10,b+25,40,20);
paneles[2].add(vbles2[j]);
}else{
vbles2[j] = new Label("Sol");
vbles2[j].setBounds(a+110,b+25,40,20);
paneles[2].add(vbles2[j]);
}
}

}
if(i == 0)
b+=50;
else
b+=25;

a = 10;
}

}




public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Simplex")){
if(!nvbles0.getText().equals("") && !necua0.getText().equals("")){
try {

paneles[0].getComponent(0).disable();
paneles[0].getComponent(1).disable();
botonera0(Integer.parseInt(nvbles0.getText())+1,Integer.parseInt(necua0.getText())+1);
}catch(NumberFormatException u){
JOptionPane.showMessageDialog(null, "Digite un número entero...", "ERROR!", JOptionPane.WARNING_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null, "No deje el campo vacío...", "ERROR!", JOptionPane.WARNING_MESSAGE);
}
}

if (e.getActionCommand().equals("Simplex Tabular")){
if(!nvbles1.getText().equals("") && !necua1.getText().equals("")){
try {
paneles[1].getComponent(0).disable();
paneles[1].getComponent(1).disable();
botonera1(Integer.parseInt(nvbles1.getText())+1,Integer.parseInt(necua1.getText())+1);
}catch(NumberFormatException u){
JOptionPane.showMessageDialog(null, "Digite un número entero...", "ERROR!", JOptionPane.WARNING_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null, "No deje el campo vacío...", "ERROR!", JOptionPane.WARNING_MESSAGE);
}
}

if (e.getActionCommand().equals("Simplex Revisado")){
if(!nvbles2.getText().equals("") && !necua2.getText().equals("")){
try {
paneles[2].getComponent(0).disable();
paneles[2].getComponent(1).disable();
botonera2(Integer.parseInt(nvbles2.getText())+1,Integer.parseInt(necua2.getText())+1);
}catch(NumberFormatException u){
JOptionPane.showMessageDialog(null, "Digite un número entero...", "ERROR!", JOptionPane.WARNING_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null, "No deje el campo vacío...", "ERROR!", JOptionPane.WARNING_MESSAGE);
}
}
}





}