I am fairly new to java and object orientated programming in general. I have been developing in perl (without oop) for a couple of years now and I am branching out to java. I just completed Head First Java and the SCJA study guide. I want to spend some time developing small applications before I sit for the exam, because I really want to make sure I know Java (and can use it). Anyway, to my point. I have a rather hard time grasping the oo concepts and I wanted to run a class structure by you guys to see if I am doing this correctly (and with proper form).
I have a simple application (it doesn't do anything yet) with 3 classes. The Main class is RisSimulator with two other classes being Main Panel and MainMenuBar. RisSimulator builds the initial gui window, creating an instance of MainPanel (which creates an instance of MainMenuBar). Is this the proper way to construct this? I have included the code below. I am really just experimenting with different things right now.
I don't see any point in your MainPanel class. It extends JPanel but doesn't modify its behaviour in any way. To put it in OO terms, you aren't using inheritance there. It could be replaced by a factory method which creates a JPanel and modifies it in a suitable way:
You'll notice that I did the same thing to your MainMenuBar class, but I didn't write the factory method (left as an exercise for the student).
I appreciate the help and pointers. I have rewritten the main class as you suggested. I guess now I am wondering, when do I break up this class? Let's say I start adding many functions to the menu bar and each one displays a different panel, maybe a form, something like that. Would I keep writing all of these helper methods in one class?
Thanks for the tips and the reading. I am reading through those articles now. Sorry about posting in the wrong forum, I wasn't sure which one to post in. I ultimately decided the Beginner one because I was more focused on understanding OO than the swing piece and now I think I am getting a better understanding of both.
Joined: May 25, 2010
I have been reading through the links you sent me and I have a couple of questions. Below is the code I have created for reference.
1) Should all calls to gui/swing functions use the SwingUtilities.invokeLater() method? Things like for instance my status bar update method? (setStatusBarMessage)
2) In regards to the SwingWorker class, is this something you would use to when creating a new JPanel or form so you don't call set Methods on that form until it is complete, or am I missing the point with this?