How to insert value of an array to a JTextfield JFrame java eclipse?

0

I am designing an eclipse application for a ticket sales point and I am working with JFrame, I need help, my problem is that I can not insert the selected item from my bus seat matrix in a JTextField to say that seat is busy I leave my code below.

This is from the matrix I have it in my class tickets // Here is where I should insert the element in my JTextfield called a7

public void setAsiento(String na){
        //En la consola si me lo imprime pero no en el JTextfield
        System.out.println(na);
        a7.setText(na);



private void muestraMatrizAsientos(int c) {
        int filas = c / 4;
        int columnas = 4;
        int extra = c % 4;
        int count = 0;
        int coun = -2;
        // System.out.println("el extra es " + extra);
        // Eliminamos los anteriores botones
        panel3.removeAll();
        Boton[][] botones;

        if (extra > 0) {
            int otro = filas + 1;

            botones = new Boton[otro][columnas];
        } else {
            botones = new Boton[filas][columnas];
        }
        for (int fila = 0; fila < filas; fila++) {
            coun = coun + 3;
            for (int columna = 0; columna < columnas; columna++) {

                botones[fila][columna]  = new Boton(60 * columna, 55 * fila, 50, 50);



                botones[fila][columna].setBounds(60 * columna, 55 * fila, 50, 50);

                count = columna + fila + coun;

                botones[fila][columna].setText(count + "");

                panel3.add(botones[fila][columna]);

            }
        }

        if (extra == 1) {
            int numcol = botones.length - 1;
            botones[numcol][0] = new Boton(60 * 0, 55 * numcol, 50, 50);

            botones[numcol][0].setText(count + 1 + "");

            panel3.add(botones[numcol][0]);

        }
        if (extra == 2) {
            int numcol = botones.length - 1;
            botones[numcol][0] = new Boton(60 * 0, 55 * numcol, 50, 50);

            botones[numcol][0].setText(count + 1 + "");

            panel3.add(botones[numcol][0]);

            botones[numcol][1] = new Boton(60 * 1, 55 * numcol, 50, 50);
            botones[numcol][1].setText(count + 2 + "");
            panel3.add(botones[numcol][1]);


        }
        if (extra == 3) {

            int numcol = botones.length - 1;
            botones[numcol][0] = new Boton(60 * 0, 55 * numcol, 50, 50);

            botones[numcol][0].setText(count + 1 + "");

            panel3.add(botones[numcol][0]);

            botones[numcol][1] = new Boton(60 * 1, 55 * numcol, 50, 50);
            botones[numcol][1].setText(count + 2 + "");
            panel3.add(botones[numcol][1]);

            botones[numcol][2] = new Boton(60 * 2, 55 * numcol, 50, 50);
            botones[numcol][2].setText(count + 3 + "");
            panel3.add(botones[numcol][2]);
        }

        panel3.updateUI();

    }

but to create the seats depends on another class called button

public class Boton extends JButton implements ActionListener{
    public boolean evento=false;


    //-------- Constructor con parametros para posicionar a los botones ------//
    public Boton( int pos_x, int pos_y, int ancho, int alto ){ 

      //  setIcon(new ImageIcon("Images/asiento.jpg"));
        //Se coloca el boton en un lugar y se le da un tamanio
        setBounds(pos_x, pos_y, ancho, alto);

        //Se agrega el action listener en este caso la misma clase
        addActionListener( this );
    }
    //------------------------------------------------------------------------//

    //---------------------- Se asigna una el nombre del boton ---------------//
    public void setNombre( int f, int c ){
        setText( f + " , " + c );

    }
    //------------------------------------------------------------------------//
    //------------------ Al darle click realizara este metodo ----------------//
    public void actionPerformed( ActionEvent e ){
        //Aqui invoco la clase boletos para tomar el valor del asiento al hacer click
        boletos bo = new boletos();
        if(!evento) {
        setBackground(Color.RED);
        evento=true;
      //  Aqui llegan los datos del click
        bo.setAsiento(getText());
        }else if(evento) {
            setBackground(Color.pink);
            evento=false;
        }


    }
    //------------------------------------------------------------------------//
}
    
asked by Carlos Osmar Rosas 01.08.2018 в 21:42
source

0 answers