hey i have written this code to make a GUI but it compile correctly but gives error at run time.
the error is
exception in thread main "java.lang.NullpointerException"
at GUI.intGUI(GUI.java:22)
at GUI.(init)(GUI.java :75)
at GUI.main (GUI.java:79)
the code is
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class GUI
{
JFrame myFrame;
JTextField tf;
JRadioButton Male,Female;
JLabel label1;
JLabel label2;
JLabel label3;
JPanel panel1;
JPanel panel2;
JPanel panel3;
public void initGUI()
{
myFrame= new JFrame();
panel1.setLayout(new GridLayout(1,2));
panel1.add(label1);
panel1.add(label2);
panel2.setLayout(new GridLayout(1,2));
panel2.add(label3);
panel2.add(tf);
JPanel panel3 = new JPanel();
ButtonGroup buttonGroup = new ButtonGroup();
Male = new JRadioButton("Male");
buttonGroup.add(Male);
panel3.add(Male);
Female = new JRadioButton("Female");
buttonGroup.add(Female);
panel3.add(Female);
Male.setSelected(true);
myFrame.add(panel1);
myFrame.add(panel2);
myFrame.add(panel3);
int initValue =60;
int minimum = 40;
int maximum = 80;
JSlider slider = new JSlider(JSlider.VERTICAL, minimum, maximum, initValue);
slider.setMinorTickSpacing(1);
slider.setMajorTickSpacing(10);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
slider.setSnapToTicks(true);
slider.setLabelTable(slider.createStandardLabels(10));
Container c=myFrame.getContentPane();
c.setLayout(new BorderLayout());
c.add(panel1,"NORTH");
c.add(slider,"CENTER");
c.add(panel2,"South");
c.add(panel3,"West");
myFrame.setDefaultCloseOperation(3);
myFrame.setSize(200,100);
myFrame.setVisible(true);
}
public GUI()
{
initGUI();
}
public static void main(String arg[])
{
GUI g=new GUI();
}
}