Results 1 to 3 of 3
Thread: How to divide code in classes?
- 12-09-2008, 06:38 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
How to divide code in classes?
Hello everyone!
I'm new to java but i have some experience in programming. I just have a really newbie question: how do i divide java code in different classes?
Let me explain it with a banal example.
I need a program that has a button and a label. When i click on the button, i the label to change its content.
This is my pseudo-code:
graphics.java:
class graphics {
private JLabel Content;
private JButton jLabelPassword;
}
actions.java:
class actions {
handler of what button does;
}
main.java:
main class {
I DON'T KNOW WHAT
}
---end---
so... can anybody please tell me how can i split code that i need in different classes. And... once i have actions and graphics, how do i start the program? What do i have to put in the main method?
Thank you and sorry for the "stupid" question. :p
- 12-09-2008, 07:01 PM #2
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
What do you see as a "concept"?
Organisation of your program into classes is largely arbitrary, and it takes a bit of practice to get a "natural feel" for where it seems right to make the split.
To start with, try and use a separate class file for things that you see as a "concept":
- things that you can "visualise" as a separate object (e.g. a window)
- things that are re-used in different parts of your app
Use inline classes or methods to additional classes for things that you see as just "uninteresting extensions or attributes" of more global/tangible objects. So for button listeners with only a few lines of code that are specific to a particular button or buttons in a particular window, just inline them there and then:
Java Code:JButton b = ... b.addActionListener(new ActionListener() { public void actionPerformed(...) {} });Neil Coffey
Javamex - Java tutorials and performance info
- 12-10-2008, 05:36 PM #3
Member
- Join Date
- Dec 2008
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Help with classes
By gnarly hogie in forum New To JavaReplies: 14Last Post: 10-10-2008, 02:29 PM -
Get name of available classes
By escuja in forum CLDC and MIDPReplies: 0Last Post: 07-26-2008, 12:03 PM -
[SOLVED] Using Code Throughout 5 Classes-Stuck
By Bascotie in forum New To JavaReplies: 46Last Post: 06-06-2008, 05:51 AM -
When do we use inner classes?
By cruxblack in forum New To JavaReplies: 5Last Post: 08-10-2007, 05:00 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks