Regarding bulding gui and widgets in java [closed]

自古美人都是妖i 提交于 2019-12-13 07:15:52

问题


I am a complete beginner in java. Although i have studied a lot of literature on the language (well sort of), this is my first real project.

I was basically planning to make a simple clock widget and later plan to build Gui s. Until now, i had learnt in swing. But then i found on this site that Swing is kinda outdated ( ref : Java GUI frameworks. What to choose? Swing, SWT, AWT, SwingX, JGoodies, JavaFX, Apache Pivot?).

What i needed was some good libraries in java to assist me in this process ( the clock widget and subsequently more complex gui). So i thought of getting libraries from jgoodies, the free ones.

And now i am utterly confused and messed up on what to do and dont understand anything. And of course i dont need books in design patterns etc etc. Just java references and some tutorials on gui using java and jgoodies to get me started. And i cant find them anywhere. So please point me in right direction.

Reading background (Head First java, java the complete ref and data structures and algo)

(Suggest others if not sufficient)


回答1:


What i needed was some good libraries in java to assist me in this process ( the clock widget and subsequently more complex gui). So i thought of getting libraries from jgoodies, the free ones.

Probably you don't need libraries as much as you think you do. Learn stuff from first principles and you will learn it better.

All the major Java GUI frameworks are quite high level and functional already. When you are first starting out, I think you should skip 3rd party libraries and see how far you get with what is provided in the base JRE and the framework of your choice. There is more than enough to learn with just the basic frameworks, the java language and the JRE. If you try to add in other frameworks too early, you will end up overloaded, confused and less productive. Plus the increased abstraction of the libraries may prevent you from learning some of the important underlying principles well enough.

Once you get a bit more experience in building things, then you will have a much better idea where the gaps in the frameworks are for your application and you can add in 3rd party libraries at that time.

planning to make a simple clock widget

If you get stuck, here is code for a JavaFX clock: How to draw a clock with JavaFX 2? or a similar implementation in Swing.

Note that creating a clock is quite a bit different than creating a traditional form based GUI that makes use of a library of predefined controls - but any of the major Java GUI frameworks can handle both tasks.

Don't make a clock your first GUI programming task, do something easier. Then try to create a clock later.

using swing for precise layout is really a difficult job

There are interactive graphical layout managers for Swing and other frameworks (e.g. the excellent SceneBuilder for JavaFX) which make this easier.

However, when first starting, it's probably worth hand coding stuff rather than letting a tool manage the layout for you (for example when learning JavaFX, stick with just the Java API and don't use FXML until you are completely comfortable with the Java API). You will learn the ins and outs of layout management and other things better that way. Sure you will make some mistakes and there will be a bit of frustration, but things will become clear in time with some persistence. And you may eventually end up deciding that you prefer hand-coding rather than using a graphical tool anyway.

The tricky part is usually creating quality, dynamically resizable GUIs that look good at different resolutions and window sizes - and that is generally tricky for beginners no matter what GUI toolkit is used.

The layout managers in JavaFX are very similar to the basic layout managers in Swing - so layout-wise there is little difference between the two frameworks.

The retained mode Scene Graph in JavaFX may be a bit easier to work with than the direct mode painting of Swing, but I guess that is not quite layout related.

Introspection tools, such as ScenicView for JavaFX, ease debugging layouts at runtime. Think of things like ScenicView as something similar to Firebug for HTML (e.g. your essential layout debugging companion).

And now i am utterly confused and messed up on what to do and dont understand anything.

You understand more than you think you do or you wouldn't have known enough to ask this question.

What you should do (IMO) is just pick a Java GUI framework (any framework - they are all passable), pick a decent starting task (something that seems mind-numbingly simple - even simpler than a clock) and start coding. Make everything task related; very small tasks with clear end-goals. Write a decent amount of code and always go back and revise your code and it's output to try to make it the very best it can be - don't settle for good enough.

Try painting rainbows and happy faces - when you code that up and see it on the screen, you will feel good about yourself :-)

If you need a refresher on the Java language, follow the Oracle Learning the Java Language trail. That trail is the way I learnt Java many years ago. It has been maintained over the years so that it is still a great resource and useful today.

If you choose Swing, follow the starting links from MadProgrammer.

If you choose JavaFX, follow the JavaFX tutorials and the Ensemble sample app but be aware that some of the JavaFX tutorials are targeted to more experienced programmers.




回答2:


AWT has effectively been replaced by Swing.

SWT is a different framework, which provides greater native interaction with the OS

JavaFX is the new player on the block, while some consider it a replacement for Swing, it's primary intention was to display Flash or act as an alternative to it.

SwingX and JGoodies are Swing based libraries.

Swing and SWT have begin around for quite some time, some might consider them to be "old", but what it does mean is there is a body of knowledge surrounding the frameworks, as well as a number libraries designed to support and extend them

JavaFX is new player on the market and has yet to build the same knowledge and support base.

If I was you. I would pay attention to Swing (personally) as it is going to provide you with the best ground base of experienced developers and support to help you on your way.

Once you become more comfortable, you could explore SWT, JavaFX and other toolkits and frameworks.

I would start with Creating a GUI with Swing, Performing Custom Painting and 2D Graphics.

My (personally) feeling is to build an understanding of the base library, try and learn it's strengths and weakness. This will help you understand when to use such libraries as SwingX and JGoodies - IMHO



来源:https://stackoverflow.com/questions/18295142/regarding-bulding-gui-and-widgets-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!