Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: component

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default component

     
    import java.awt.FlowLayout;
     
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JCheckBox;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
    public class hyperlikntest extends JComponent{
     
    	public static void main(String [] args){
     
    		Box f = new Box(BoxLayout.Y_AXIS);
    		int NumOfRperP=10;
    		JPanel[] p = new JPanel[NumOfRperP];
    		JCheckBox[] c = new JCheckBox[NumOfRperP];
    		JTextField[] t = new JTextField[NumOfRperP];
     
     
    		for (int i =0; i< NumOfRperP; i++){
    			t[i].setColumns(50);
    			p[i].setLayout(new FlowLayout(FlowLayout.LEFT));
    			p[i].add(c[i]);
    			p[i].add(t[i]);	
    			f.add(p[i]);
    		}
     
    		f.setVisible(true);
     
    	}
     
    }


  2. #2
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: component

    noooooooo answer

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: component

    Quote Originally Posted by nasi View Post
    noooooooo answer
    What is the question?

  4. #4
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: component

    when I execute the above code it generates :

    "Exception in thread "main" java.lang.NullPointerException
    at test.hyperlikntest.main(hyperlikntest.java:29)"

    I was wondering what is the reason

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: component

    The code creates an array, but doesn't instantiate the objects of that array

    JPanel[] panels = new JPanel[1];
    panels[0].add(new JComponent());//throws a null pointer exception because panels[0] was never instantiated
    panels[0] = new JPanel();//instantiate
    panels[0].add( new JComponent() );//now it works like a charm

  6. The Following User Says Thank You to copeg For This Useful Post:

    nasi (April 4th, 2010)

Similar Threads

  1. Replies: 3
    Last Post: February 1st, 2010, 12:24 AM
  2. Component/Widget creation
    By Hellops in forum AWT / Java Swing
    Replies: 0
    Last Post: October 15th, 2009, 10:31 PM
  3. How to Use the JList component - Java Swing
    By neo_2010 in forum Java Swing Tutorials
    Replies: 1
    Last Post: July 11th, 2009, 04:02 AM
  4. Com based component project using Java
    By jazz2k8 in forum Java Native Interface
    Replies: 1
    Last Post: October 7th, 2008, 10:54 PM

Tags for this Thread