i have jst started programing in java m beginer.
m making gui which contains a two radio button a slider and a text message.
although its compiling coreectly but it doesnot display any thing

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class GUI
{
JFrame frame;
JLabel coord;
JRadioButton Man=new JRadioButton("man");
JRadioButton Woman= new JRadioButton("woman");
JSlider slider;

public void initGUI()
{
frame=new JFrame();
Container cont=frame.getContentPane();
cont.setLayout(new BorderLayout());
cont.add(Man);
cont.add(Woman);
cont.add(slider);
JTextField numberEnter = new JTextField("ideal weight is:", 20);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setVisible(true); 
}
public static void main (String arg[])
{
GUI g=new GUI();
}
}

oh i got that. but now i have got some other error in running it. it compiles successfully. first error is some nullpointer error.

some nullpointer error.

The error message tells you exactly where the error happened. If you post the complete error message here we can have a look at it for you, but first look yourself at the line in your file that it gives you, and look for an uninitialised variable being used on that line.

You also may want to correct...

cont.add(Man);
cont.add(Woman);
cont.add(slider);

You are NOT specifying WHERE on your JPanel you want to put these (since you are using a BorderLayout).

Edited 5 Years Ago by hfx642: n/a

This article has been dead for over six months. Start a new discussion instead.