I'm here to see if you can enlighten me with this Java and the GUI I'm just learning.
I'm trying to make a simple 3-section GUI (header, content and footer).
Generate the following code (note, it is not the complete program and I know there are variables that are not used)
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();
}
}
But when I want to preview the progress this does not run.
This is the error I get.
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
In case it is important, I attach the versions of Netbeans, JDK and 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
Greetings and thanks in advance