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 4 of 4

Thread: Netbeans and inner classes/variable access

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Netbeans and inner classes/variable access

    Not sure if this is the right place to post but it seems most relevant. So basically i create a java form in netbeans. I create a couple of textfields, lets say 'textField1' and 'textField2'. I then create another java class called 'test'(seperate file), im assuming they're inner classes? I just right click on the package and create new class. Anyway, the class 'test' can't access/read 'textField1' and 'textField2', why is that? If 'test' is an inner class, shouldnt it have access to all of the variables and declarations within that were made in the form such as the 2x textfields? In textpad if i create a class within a class in the one file, anything declared in the outside class can be accessed from the inner class. I'm not sure whats wrong? Only just changed to netbeans any help would be appreciated =]


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Netbeans and inner classes/variable access

    Why do you assume that it's an inner class?

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Netbeans and inner classes/variable access

    Quote Originally Posted by KevinWorkman View Post
    Why do you assume that it's an inner class?
    I was told that the inner classes are kept in seperate files? I guess it's not? any idea on how to create an inner class in netbeans?
    edit: Ok, so you can just create an inner class inside the main class in the same file, but is there a way to put innerclasses in a seperate file? so it isnt so messy?
    Last edited by jmorr212; December 17th, 2010 at 09:13 PM.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Netbeans and inner classes/variable access

    Java classes are called "inner classes" because they are truly inside the definition of a Java class. I don't know of a way to get around this (Java doesn't allow you to put the definition of a class into multiple files).

    What you could do is create classes in the same package which have default permissions. This allows all the other classes in that package to have access to that class, but no other classes can access that class.

Similar Threads

  1. access restriction??? wtf!?!
    By wolfgar in forum Java Theory & Questions
    Replies: 6
    Last Post: November 23rd, 2009, 07:27 AM
  2. Default Access (package access) confusion
    By gauravrajbehl in forum Java Theory & Questions
    Replies: 1
    Last Post: November 18th, 2009, 04:11 AM
  3. Access the Same Socket
    By ahmmnhwa in forum Java Networking
    Replies: 5
    Last Post: October 29th, 2009, 11:50 AM
  4. Netbeans help
    By [Kyle] in forum Java IDEs
    Replies: 2
    Last Post: September 20th, 2009, 06:32 PM
  5. How to share variable values amongst different classes?
    By igniteflow in forum Object Oriented Programming
    Replies: 8
    Last Post: August 20th, 2009, 08:53 AM