Results 1 to 6 of 6
  1. #1
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    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

    Java 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
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    So Do you have problem with this task? What can not you do?
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default

    my code is working fine there is no error but i want only to separate it into another java file so that is will become more easier to read.

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    I clearly understand what you want make. You can use pattern MVC for this aim.
    I looked on your code. It is very short. You have only 20 statement and it is all and I can excellent read this code.
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    I would suggest that this:
    Java Code:
              String user =  new propAct().readSetting("pu")
             ,pass = new propAct().readSetting("wp");
              String usnam_decrypt = new cryptobrk().decrypt(user),
              pass_decrypt = new cryptobrk().decrypt(pass);
    is less readable than this:
    Java Code:
              String user =  new propAct().readSetting("pu");
              String pass = new propAct().readSetting("wp");
              String usnam_decrypt = new cryptobrk().decrypt(user);
              String pass_decrypt = new cryptobrk().decrypt(pass);


    You also need to be a little more careful with indentation and style.But beyond that, I agree with Petr that you don't need to worry about length yet. You might at some point want a User class, but length of code is not the reason.

    -Gary-

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Just to be a little clearer:
    Quote Originally Posted by Jhovarie View Post
    Note i mean that i want to separate the code into another java file. from NewJFrame.java to initialize.java
    Classes don't work like that. If your JFrame needs initialization code, you can't split that off into another class. You can perhaps split code into other methods within your class, and that's often a very good idea. Many of the variables within your constructor should probably be instance variables (fields) of your class. If you design things this way, you can move some of this code into a readProperties() method, for instance. As it is now, these variables you're assigning values to will disappear as soon as the constructor finishes executing.

    -Gary-

Similar Threads

  1. Deleted Class template code. Now I cant make class.
    By AcousticBruce in forum IntelliJ IDEA
    Replies: 0
    Last Post: 01-11-2011, 11:52 PM
  2. Using separate methods
    By Shyamz1 in forum New To Java
    Replies: 0
    Last Post: 10-31-2010, 06:31 PM
  3. Separate file for main and class
    By eel in forum New To Java
    Replies: 12
    Last Post: 09-18-2010, 09:24 AM
  4. How to make swing.Timer as a separate class
    By nethz13 in forum New To Java
    Replies: 9
    Last Post: 04-18-2010, 10:14 AM
  5. Should I separate my code into separate files?
    By Inks in forum New To Java
    Replies: 0
    Last Post: 03-26-2009, 01:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •