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

Thread: Best way to turn a single class into multiple classes

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Best way to turn a single class into multiple classes

    Hello Guys

    I'm still a beginner to Java and have written a programme for an assignment which is a GUI with a key pad that registers when you press a buttons on the Keypad. Type a password to unlock the programme and then type a password to unlock the programme.

    It's working fine but when it's in the one single class but I need to break it into 2-3 classes but I'm having difficulty doing this successfully.

    The class is made up of an arrayList to create the buttons for the Keypad and an arrayList to create the actionsListeners. I keep on running into nullPointerExceptions. Referencing things that have null values!

    What are your recommendations to to do this the most efficiently

    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Best way to turn a single class into multiple classes

    do this the most efficiently
    I'd use cut and paste.
    Find sections of code that do a single function that is easily given a name, that can take parameters and return a value, cut the code and paste it into a method and replace the cut section with a call to the new method.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Best way to turn a single class into multiple classes

    Quote Originally Posted by Norm View Post
    I'd use cut and paste.
    Find sections of code that do a single function that is easily given a name, that can take parameters and return a value, cut the code and paste it into a method and replace the cut section with a call to the new method.
    Thanks, that what my problem was I was trying to take too much when I should of been just using small spinets of code and turning them into methods.

Similar Threads

  1. Hey guys, I'm having a little trouble working with multiple classes.
    By worsewicked in forum Object Oriented Programming
    Replies: 4
    Last Post: January 18th, 2012, 08:03 PM
  2. Can single MDB subscribe multiple topics?
    By shptlucky in forum Web Frameworks
    Replies: 0
    Last Post: April 22nd, 2011, 05:52 AM
  3. Conversion from multiple ints to single string
    By surfbumb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2011, 10:08 PM
  4. help with using multiple classes
    By finalfantasyfreak15 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 5th, 2011, 12:18 AM
  5. Replies: 6
    Last Post: May 15th, 2009, 05:06 PM