I can not get my Java button to show inside my JFrame

0

The problem is that I have the JFrame and it is perfect, with its title and others. When I try to instantiate a button, it does not appear in any coordinate that adds it.

    package neuronaia;

    import javax.swing.*;

    public class MainWindow extends JFrame{

public static void main(String[] args) {
    // TODO Auto-generated method stub

    JFrame Ap = new JFrame();
    Ap.setLayout(null);
    Ap.setSize(500,500);
    Ap.setTitle("Aprendizaje");
    Ap.setDefaultCloseOperation(Ap.EXIT_ON_CLOSE);
    Ap.setVisible(true);
    Ap.setLocationRelativeTo(null);

    JButton button1 = new JButton("Aceptar");
    button1.setBounds(15, 15, 45, 15);      



}

}
    
asked by Juan Pimentel 07.09.2017 в 20:48
source

1 answer

0

The problem is that in that code you do not add the button that you create to the panel. To do this you must add the following:

Ap.add(button1);
    
answered by 07.09.2017 в 22:54