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: how to separate this code in another class

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

    Default how to separate this code in another class

    Hello every one i have a simple problem here i want to separate this code so that my code will become more easy to read. im using netbeans hear is my code

    public class NewJFrame extends javax.swing.JFrame{
    boolean logstart = false;
        public NewJFrame() throws IOException {
          initComponents();
    // it is hard to develop application if the code are long so i want to separate this to another //external class plss help...
    //Start here  ----------------------------------------
           setContentPane(jPanel1);
            try{
           int x = Integer.parseInt(new propAct().readSetting("locatefx"));
           int y = Integer.parseInt(new propAct().readSetting("locatefy"));
           String auto = new propAct().readSetting("auto");
           if(auto.equals("true")){
               automaticsignin.setSelected(true);
              String user =  new propAct().readSetting("pu")
             ,pass = new propAct().readSetting("wp");
              String usnam_decrypt = new cryptobrk().decrypt(user),
              pass_decrypt = new cryptobrk().decrypt(pass);
              System.out.println(usnam_decrypt);
              System.out.println(pass_decrypt);
           }
          String user =  new propAct().readSetting("pu");
           String usnam_decrypt = new cryptobrk().decrypt(user);
           jTextField1.setText(usnam_decrypt);
           setLocation(x,y);
            }catch(Exception e){
            new propAct().newSetting("pu", "");
            new propAct().newSetting("wp", "");
            }
    //End here ----------------------------------------------------------------
        }
        @SuppressWarnings("unchecked")
      //Generated Code

    Note i mean that i want to separate the code into another java file. from NewJFrame.java to initialize.java


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: how to separate this code in another class

    Have you ever used multiple classes before? Here is a quick example:

    public class Class1 {
    	/**
    	 * JavaProgrammingForums.com
    	 */
    	public static void main(String[] args) {
     
    		Class2 c2 = new Class2();
     
    		System.out.println("Hello, my name is " + c2.name);
    		System.out.println("My favourite number is " + c2.myInt);
     
    		c2.link();
     
    	}
    }

    public class Class2 {
     
    	int myInt = 420;
    	String name = "Mary";
     
    	static void link(){
    		System.out.println("JavaProgrammingForums.com");
    	}
    }

    Output:
    Hello, my name is Mary
    My favourite number is 420
    JavaProgrammingForums.com
    I know this is a very basic example but using this you should be able to work out how to move forward..
    Try it and let us know when you get stuck.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. The Following User Says Thank You to JavaPF For This Useful Post:

    Jhovarie (February 28th, 2011)

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

    Default Re: how to separate this code in another class

    Wow this is very good sample thanks

Similar Threads

  1. Help requested - testing a class with a tester class, no methods allowed.
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 10:40 PM
  2. What is wrong with this code class not found
    By newbieJava in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 19th, 2011, 06:39 PM
  3. separate strings
    By ridg18 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 21st, 2011, 06:22 AM
  4. Connect class with code?...?
    By truebluecougarman in forum Java Theory & Questions
    Replies: 6
    Last Post: January 20th, 2011, 08:13 PM
  5. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM