You never initialize the home variable to any object so it makes sense that you'll see a NPE if you try to call methods off of it.
i.e.,
// this declares a variable but doesn't assign anything to it
JFrame home; // home is not assigned and is currently null
and not
// this both declares a variable and assigns an object reference to it.
JFrame home = new JFrame();
Also why do you have the class extend JFrame and then try to create another one inside the class?
Regarding "beautiful" code -- you will want to learn Java's code formatting rules. You shouldn't indent code randomly but rather all code in a single block should be indented the same amount.
Regarding:
I read that it is because you didnt asign a value, or null cant be used as a value but WTF, I mean Im almost sure my code is written correctly.
This means that you don't yet understand what it means to "assign a value" which is different from declaring a variable (see above) and which is well explained in the first pages of most any intro to Java book. Note that Swing GUI programming is a fairly advanced branch of Java programming, and you will likely be better off first going through some basic tutorials of books before jumping into GUI programming.
This would be another way to create a GUI similar to what you tried to create:
import java.awt.Dimension;
import javax.swing.*;
@SuppressWarnings("serial")
public class MathmePanel extends JPanel {
private static final int PREF_W = 600;
private static final int PREF_H = 500;
public MathmePanel() {
// create my GUI here
}
// set size in a flexible and safe way
@Override
public Dimension getPreferredSize() {
Dimension superSize = super.getPreferredSize();
if (isPreferredSizeSet()) {
return superSize;
}
int prefW = Math.max(PREF_W, superSize.width);
int prefH = Math.max(PREF_H, superSize.height);
return new Dimension(prefW, prefH);
}
private static void createAndShowGui() {
MathmePanel mainPanel = new MathmePanel();
// create JFrame rather than override it
JFrame frame = new JFrame("Pruebax1");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
// Start Swing GUI in a safe way on the Swing event thread
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}