I think a lot of this is definately a question of personal programming
style, but I'm new to Java and would like to hear a few opinions.
I'm writing a control panel for an application that runs separately. The
control panel is basically (almost) fully self contained. It consists of a
tabbed pane with 5 different tabs. Each tab has a number of different
controls -- basically all the "commonly used" controls (buttons, lists,
comboboxes, text input...). For a number of components it is easiest for
me to use anonymous or other inside classes. I'm also using private
classes (each tab pane is created by a private class in the same file as
the main GUI class).
So for a project like this, do most people write the code for the entire
window as 1 class, or a separate class for each panel? Is there any kind
of guideline about when a class gets too big? It seems to me any class
creating a window and adding controls will be rather large, since so many
things are done for each component (specifying min, max & preferred size,
adding listeners, specifying list objects, etc), so I would think almost
any class that contains a window would be big anyway.
So how would other people determine what goes in one class and in another,
or if they use private classes in a case like this?
Thanks!
Hal 5 2980
"Hal Vaughan" <ha*@thresholdd igital.com> wrote in message
news:Js87b.2932 35$Oz4.81794@rw crnsc54... I think a lot of this is definately a question of personal programming style, but I'm new to Java and would like to hear a few opinions.
I'm writing a control panel for an application that runs separately. The control panel is basically (almost) fully self contained. It consists of
a tabbed pane with 5 different tabs. Each tab has a number of different controls -- basically all the "commonly used" controls (buttons, lists, comboboxes, text input...). For a number of components it is easiest for me to use anonymous or other inside classes. I'm also using private classes (each tab pane is created by a private class in the same file as the main GUI class).
So for a project like this, do most people write the code for the entire window as 1 class, or a separate class for each panel? Is there any kind of guideline about when a class gets too big? It seems to me any class creating a window and adding controls will be rather large, since so many things are done for each component (specifying min, max & preferred size, adding listeners, specifying list objects, etc), so I would think almost any class that contains a window would be big anyway.
So how would other people determine what goes in one class and in another, or if they use private classes in a case like this?
Thanks!
Hal
I would probably use a class for the "parent" window with the tabbed pane
and use a separate class for each of the 5 options. These will share
characteristics so I would probably use a common superclass for these 5 to
avoid retyping the same stuff 5 times. I don't know of any particular
guidelines, but I seldom write a class larger than 500 lines. I also tend to
move actionlisteners into a separate class to avoid mess. I would also
recommend using private classes sparingly. I find it much easier to deal
with them separately.
John
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003
I have done this sort of thing only once and I use
a separate class for each tab. I like to keep my files
relatively small too, but the guy I work with keeps
making huge files that go on forever.
"John Court" <-> wrote in message
news:3f******** *************** @lovejoy.zen.co .uk... "Hal Vaughan" <ha*@thresholdd igital.com> wrote in message news:Js87b.2932 35$Oz4.81794@rw crnsc54... I think a lot of this is definately a question of personal programming style, but I'm new to Java and would like to hear a few opinions.
I'm writing a control panel for an application that runs separately.
The control panel is basically (almost) fully self contained. It consists
of a tabbed pane with 5 different tabs. Each tab has a number of different controls -- basically all the "commonly used" controls (buttons, lists, comboboxes, text input...). For a number of components it is easiest
for me to use anonymous or other inside classes. I'm also using private classes (each tab pane is created by a private class in the same file as the main GUI class).
So for a project like this, do most people write the code for the entire window as 1 class, or a separate class for each panel? Is there any
kind of guideline about when a class gets too big? It seems to me any class creating a window and adding controls will be rather large, since so
many things are done for each component (specifying min, max & preferred
size, adding listeners, specifying list objects, etc), so I would think almost any class that contains a window would be big anyway.
So how would other people determine what goes in one class and in
another, or if they use private classes in a case like this?
Thanks!
Hal
I would probably use a class for the "parent" window with the tabbed pane and use a separate class for each of the 5 options. These will share characteristics so I would probably use a common superclass for these 5 to avoid retyping the same stuff 5 times. I don't know of any particular guidelines, but I seldom write a class larger than 500 lines. I also tend
to move actionlisteners into a separate class to avoid mess. I would also recommend using private classes sparingly. I find it much easier to deal with them separately.
John
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/2003
"John Court" <-> wrote in message I would probably use a class for the "parent" window with the tabbed pane and use a separate class for each of the 5 options. These will share characteristics so I would probably use a common superclass for these 5 to avoid retyping the same stuff 5 times. I don't know of any particular guidelines, but I seldom write a class larger than 500 lines. I also tend to move actionlisteners into a separate class to avoid mess. I would also recommend using private classes sparingly. I find it much easier to deal with them separately.
John
That's an interesting approach. I wonder, if you have a separate
class for your action listener, and it needs to reference other
information on the UI, how do you pass along that information?
For a contrived example, you have a textbox for text, a textfield for
a filename, and a "save" button. So the actionListener for the button
is in a separate class. That's fine... but then you have to set
fields within the action listener class so that it can access the
textbox and textfield, or some other similar overhead (not that that's
a whole lot of overhead).
My approach is either that it's an independent operation, in which
case I might extend JButton with a class that implements
actionListener, or when everything is somehow related, I have my GUI
class implement the actionListener (especially in this case - where
there's only one thing listening anyway). Now, the GUI class, in this
case, might just be another compound component - one of the tab panes,
for example. I have some programs that do database work and I have a
reusable component to display the records in a JTable with options to
refresh the display or remove a record - I use this in several
programs. It's simple enough that (with only two buttons), that I
implemented the actionListener within that class, and just check to
see which button was pressed.
I guess what I'm saying is that I wouldn't always do it the same way,
I'd have to know more about the context of the program. I like to
think of things as either being related (in which case I might put the
actionListener within the GUI class) or as being independent (in which
case I might put it in a separate class). But if I were putting it in
a separate class, I'd just implement my own component - extending a
component and implementing an actionListener. Then that makes for
reusable components.
For this example, the five tab panes, I'd have to know more, but I'd
probably at least put each pane in a separate class, and if they are
simple enough I'd implmenet the actionListener within the class. Just
my $0.02.
Hal,
Large classes are very complicated, and hard to understand. Primarily
because there is a lot of code and it's doing lots of things.
Further, everything in your program has access to everything else.
This sort of design makes it hard to change things without have other
dependancies that must also change. Smaller classes do less things,
and are easier to understand and maintain. If there's not a lot of
code there then it can't be doing to much.
Your question is a very good question to ask. If you look at all the
Swing books out there, they're more concerned with telling you the API
than best practices or how to make the API easy to use. Very few
people seemed to know how to structure Swing apps so that it's easy to
change and modify them.
I would recomend you seperate your classes in logical units.
Everything dealing with X in one "place", and everything dealing with
Y in another. In your program X and Y might be subclasses of panels
or classes that contain the components in 1 of the 5 tabs. When I say
place I mean a class or a set of related classes. Now what glues X
and Y together, so that it creates a complete program, should be the
responsiblity of another class. Generally, this is called the
controller in MVC terms. He should be in charge of creating instances
of X, Y, and maybe some high level actions. In your program he'd
probably create the tabs and the JFrame. He should also control the
model for your program. Then he can hand the right parts of the model
to each view component or control access to it. Should he be adding
listeners on the sub panels or controls within X and Y? Probably not.
Let the X and Y be responsible for responding to changes in their UI,
and have them call a method on the controller in order to accomplish
the business logic and manipulate the model. Seperating these
concerns from each other makes it esaier to modify the internals of X
or Y without impacting any other part of your program.
It doesn't sound like your program is too complicated, but it's good
that you're thinking about these sorts of issues. I have been doing
Swing for 4 years now, and I learned all of this the hard way.
good luck
charlie
Hal Vaughan <ha*@thresholdd igital.com> wrote in message news:<Js87b.293 235$Oz4.81794@r wcrnsc54>... I think a lot of this is definately a question of personal programming style, but I'm new to Java and would like to hear a few opinions.
I'm writing a control panel for an application that runs separately. The control panel is basically (almost) fully self contained. It consists of a tabbed pane with 5 different tabs. Each tab has a number of different controls -- basically all the "commonly used" controls (buttons, lists, comboboxes, text input...). For a number of components it is easiest for me to use anonymous or other inside classes. I'm also using private classes (each tab pane is created by a private class in the same file as the main GUI class).
So for a project like this, do most people write the code for the entire window as 1 class, or a separate class for each panel? Is there any kind of guideline about when a class gets too big? It seems to me any class creating a window and adding controls will be rather large, since so many things are done for each component (specifying min, max & preferred size, adding listeners, specifying list objects, etc), so I would think almost any class that contains a window would be big anyway.
So how would other people determine what goes in one class and in another, or if they use private classes in a case like this?
Thanks!
Hal
Thanks to all those who responded (I can't respond to the original now, it's
off my server -- I've been off line and on Gilligan's Island -- no light,
no power, no 'lectricity, just like Robinson Crusoe -- thanks to Isabel and
9 days without power!). There are some really helpful points and answers,
not just on this response, but in the other branch of this thread.
I am almost completely self-taught (I took a few courses back in the early
80s, but that was mainly FORTRAN and Assembler), so I've been picking up
things like structured programming on my own and it is really helpful to
hear other people talk about how they do things.
Thanks for the comments!
Hal This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David MacQuigg |
last post by:
I have what looks like a bug trying to generate new style classes with
a factory function.
class Animal(object): pass
class Mammal(Animal): pass
def newAnimal(bases=(Animal,), dict={}):
class C(object): pass
C.__bases__ = bases
dict = 0
|
by: Vaibhav |
last post by:
I recently heard about 'new-style classes'. I am very sorry if this
sounds like a newbie question, but what are they? I checked the Python
Manual but did not find anything conclusive. Could someone please
enlighten me? Thanks!
|
by: Kalle Anke |
last post by:
I'm confused by the concepts of old-style vs new-style classes, I've read
most of the documents I found about this but it doesn't "click". Probably
because I wasn't around before 2.2.
Anyway, the reason for new style classes are to make the whole type/object
thing work better together. There are a number of new features etc.
I think my problem is when new-style classes are used, at first I thought
that all classes become new-style...
|
by: venk |
last post by:
Hi,
can some one properly explain the differences between class types and
classic classes? ... Still face problems in identifying what is what.
|
by: ankit |
last post by:
Hello,
Please put some light on, What are new style classes and classic style
classes in python. The basic differences in them. And How can I decide
to choose one.
| |
by: Chris F Clark |
last post by:
Please excuse the length of this post, I am unfortunately long-winded,
and don't know how to make my postings more brief.
I have a C++ class library (and application generator, called
Yacc++(r) and the Language Objects Library) that I have converted over
to C#. It works okay. However, in the C# version, one has to build
the class library into the generated application, because I haven't
structured this one thing right. I would like to...
|
by: wolfing1 |
last post by:
Is there a way to see what CSS classes in a page are not defined? (like
if I want to find mispelled class names, etc)
|
by: allendowney |
last post by:
Hi All,
I am working on a revised edition of How To Think Like a Computer
Scientist,
which is going to be called Think Python. It will be published by
Cambridge
University Press, but there will still be a free version under the GNU
FDL.
You can see the latest version at thinkpython.com; I am revising now,
|
by: Joseph Barillari |
last post by:
Hi python-list,
I've just started using new-style classes and am a bit confused as to
why I can't seem to alter methods with special names
(__call__, etc.) of new-style class instances. In other words, I
can do this:
.... pass
....
33
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |