Results 1 to 6 of 6
- 02-27-2011, 03:45 PM #1
Banned
- Join Date
- Feb 2011
- Posts
- 65
- Rep Power
- 0
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
Note i mean that i want to separate the code into another java file. from NewJFrame.java to initialize.javaJava 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
- 02-27-2011, 04:06 PM #2
So Do you have problem with this task? What can not you do?
Skype: petrarsentev
http://TrackStudio.com
- 02-28-2011, 04:13 PM #3
Banned
- Join Date
- Feb 2011
- Posts
- 65
- Rep Power
- 0
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.
- 03-01-2011, 09:20 AM #4
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
- 03-01-2011, 05:02 PM #5
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
I would suggest that this:
is less readable than 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);
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-
- 03-01-2011, 05:08 PM #6
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Just to be a little clearer:
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
-
Deleted Class template code. Now I cant make class.
By AcousticBruce in forum IntelliJ IDEAReplies: 0Last Post: 01-11-2011, 10:52 PM -
Using separate methods
By Shyamz1 in forum New To JavaReplies: 0Last Post: 10-31-2010, 05:31 PM -
Separate file for main and class
By eel in forum New To JavaReplies: 12Last Post: 09-18-2010, 08:24 AM -
How to make swing.Timer as a separate class
By nethz13 in forum New To JavaReplies: 9Last Post: 04-18-2010, 09:14 AM -
Should I separate my code into separate files?
By Inks in forum New To JavaReplies: 0Last Post: 03-26-2009, 12:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks