Questo è un semplice codice per testare i panel:
l'errore che ottengo è:
Exception in thread "main" java.lang.NullPointerException
at mio2.<init>(mio2.java:48)
at mio2.main(mio2.java:68)
Press any key to continue...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
public class mio2 extends JFrame
{
private JPanel pannelloSCUp;
private JPanel pannelloSCCenter;
private JPanel pannelloSCDown;
private JButton button1 = new JButton("p1");
private JButton button2 = new JButton("p2");
private JButton button3 = new JButton("p3");
public mio2()
{
setLayout(new GridLayout(3,1));
setTitle("Titolo del software");
//line 48
pannelloSCUp.setLayout(new FlowLayout());
pannelloSCUp.setBackground(Color.pink);
pannelloSCUp.add(button1);
pannelloSCCenter.setLayout(new FlowLayout());
pannelloSCCenter.setBackground(Color.red);
pannelloSCCenter.add(button2);
pannelloSCDown.setLayout(new BorderLayout());
pannelloSCDown.setBackground(Color.green);
pannelloSCDown.add(button3);
this.getContentPane().add(pannelloSCUp);
this.getContentPane().add(pannelloSCCenter);
this.getContentPane().add(pannelloSCDown);
}
// Main method
public static void main(String[] args)
{
//line 68
mio2 frame = new mio2();
frame.setSize(800, 600);
frame.setVisible(true);
}
}