Recurro aquí a ver si me pueden iluminar con esto de Java y las GUI que estoy aprendiendo recién.
Estoy tratando de hacer una GUI sencilla de 3 secciones (encabezado, contenido y pie).
Genere el siguiente código (ojo, no es el programa completo y se que hay variables sin usar)
package grilla;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Remun extends JFrame{
private JFrame ventana;
private JButton sumaHab, sumaDesc;
private JLabel texto1, tituloEnc;
private JCheckBox check1;
private JTextField ingreso1,totalHab,totalDesc,totalAPagar;
private JPanel panelEnc,panelFoot;
public Remun(){
pantalla();
encabezado();
footer();
}
public void encabezado(){
panelEnc=new JPanel();
tituloEnc=new JLabel("Sistema de Remuneraciones");
panelEnc.setLayout(new FlowLayout());
panelEnc.add(tituloEnc);
}
public void footer(){
panelFoot=new JPanel();
sumaHab=new JButton("Sumar Haberes");
sumaDesc=new JButton("Sumar Descuentos");
panelFoot.setLayout(new FlowLayout());
panelFoot.add(sumaHab);
panelFoot.add(totalHab);
panelFoot.add(sumaDesc);
panelFoot.add(totalDesc);
panelFoot.add(totalAPagar);
}
public void pantalla(){
ventana=new JFrame("Remuneraciones");
ventana.setLocationRelativeTo(null);
ventana.setLayout(new GridLayout());
ventana.add(panelEnc);
ventana.add(panelFoot);
ventana.pack();
ventana.setVisible(true);
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
Remun g1 = new Remun();
}
}
Pero cuando quiero previsualizar los avances este no se ejecuta.
Este es el error que obtengo.
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1095)
at java.awt.Container.add(Container.java:1007)
at javax.swing.JFrame.addImpl(JFrame.java:567)
at java.awt.Container.add(Container.java:419)
at grilla.Remun.pantalla(Remun.java:46)
at grilla.Remun.<init>(Remun.java:17)
at grilla.Remun.main(Remun.java:54)
Java Result: 1
Por si es importante, adjunto las versiones de Netbeans, JDK y JRE
Product Version: NetBeans IDE 8.0.2 (Build 201411181905)
Java: 1.8.0_191; Java HotSpot(TM) 64-Bit Server VM 25.191-b12
Runtime: Java(TM) SE Runtime Environment 1.8.0_191-b12
Saludos y agradecimientos de antemano