Skip to main content
gamedev.net
🔒 Locked

[java] a better understanding

Started by rkazuhiro 3 replies 300+ views
Original Post
rkazuhiro
rkazuhiro
Okay...I''ve been studying Java, and of course writing little programs. But I am making the step up now, and I have the paper design down for a real SWING program. But my problem...where do I start? Well, actually, not where to start, but where do I begin seperating GUI code with other code? When I learned C++, reading other peoples code helped me separate the code into logical chunks, functions, et cetera. But with Java, I can never seem to find a program that actually breaks things up. Mainly because they are too small, or they are applets and do not apply. I''m writing a regular program, not an applet. For example, when I design a GUI program in C++(I use Qt), there is a main function, where I just bring up the code to initialize, setup the GUI, and call a program loop. But in Java, many of the tutorials throw all of this into one big class. The main segment of code is really simple, and normally consists of only functions, and is very easy to follow. But with Java, I have not seen this. To me it all looks like chaos, even the examples SUN uses. So I was wondering where I might be able to find some code of significant length, where I could see some real style and form. My program is rather simple, it''s just a GUI interface for doing serial port transfers(but has to run on Solaris, Linux, and windows computers). So I chose to use Java, instead of having to learn MOTIF and MFC. I''ve always wanted to do something with Java anyways.
linkki_
linkki_
You might want to know something about design patterns, but here is a quick and dirty solution for you:

1)Create a frame class that includes all gui-stuff and listens to users actions.
2)Create a main function to that frame class, and create an instance of your frame in it.
3)Create one or more non-gui classes and call their appropriate methods whenever user does something.

If you have more than one window in your gui, make a new class and and possibly also a control class for non-gui related stuff for each.
draqza
draqza
If you want to find java app source code you might try www.sourceforge.net. Oh, and it''s nice to see someone that actually says they''re writing a regular program instead of an applet, I can''t believe how many people (java programmers, even) there are that don''t realize that''s possible.
WNDCLASSEX Reality;......Reality.lpfnWndProc=ComputerGames;......RegisterClassEx(&Reality);Unable to register Reality...what's wrong?---------Dan Uptonhttp://0to1.orghttp://www20.brinkster.com/draqza
cyrax256
cyrax256
Personally, I enjoy much more doing stand-alone application than applets... Sure, you can´t have as many people using it as the applets (because it´s difficult to convince someone to download the JRE :-P), but the absence of security restrictions in the applications make Java a powerful tool, and an incredibly easy one!

Well, rkazuhiro, you´ve been replied with the basics of a Swing application... To me, a good separation of code and GUI is a program that I can be able to convert it to a console application (text) and still can be useful (I mean, you can still use the same methods you used for the graphical version), I don´t know if others share this opinion...

gandalfy
gandalfy
You could try having a look at the Model-View-Controller pattern. To put it short, a pattern is a common solution to a common problem.
The M-V-C pattern is a good solution to the problem of seperating Gui(View) code from algorithms(Model) and the logic controlling the algorithms (Controller).

There are alot of different patterns which can solve different problems.

Here is an url for the M-V-C pattern





[edited by - gandalfy on May 25, 2002 8:57:15 PM]

[edited by - gandalfy on May 25, 2002 8:57:48 PM]
-x-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.