No controls are displayed in JAVA only the JFrame

1

How about, I have the following code but at the time of executing it, only the window is seen and no control is displayed, could you help me?

Operations Class

public class Operaciones {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Ventana venta=new Ventana();
    venta.setVisible(true);
}

}

Window Class

    import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Ventana extends JFrame{

    //private static final long serialVersionUID = 1L;
    private JLabel lbl1=new JLabel("Numero 1");
    private JLabel lbl2=new JLabel ("Numero 2");
    private JLabel lblResultado=new JLabel("Resultado");

    private JTextField txt1=new JTextField();
    private JTextField txt2=new JTextField();

    private JButton btnSuma=new JButton("+");
    private JButton btnResta=new JButton("-");
    private JButton btnMultiplicacion=new JButton("*");
    private JButton btnDivision=new JButton("/");


    private Container c= getContentPane();

    public Ventana(){
        super.setTitle("Operaciones");//título de la ventana 
        super.setSize(320, 480);//tamaño de la ventana
        super.setDefaultCloseOperation(EXIT_ON_CLOSE);//libera la memoria

        cargarControles();
    }

    private void cargarControles() {
        c.setLayout(null);

        lbl1.setBounds(10,10,300,20);
        txt1.setBounds(10,40,300,40);

        lbl2.setBounds(20, 20, 300, 20);

    }
}
    
asked by Guillermo Ricardo Spindola Bri 31.08.2016 в 20:12
source

1 answer

2

You have to add the components to the JFrame in this case you would use the add example method

    private void cargarControles() {
       c.setLayout(null);

        lbl1.setBounds(10,10,300,20);

        txt1.setBounds(10,40,300,40);

        lbl2.setBounds(20, 20, 300, 20);

        this.add(lbl1);
        this.add(lbl2);
        this.add(lblResultado);
        this.add(txt1);
}
    
answered by 31.08.2016 / 20:18
source