开发者

Learning Java Swing (GUI builder or not?) [closed]

开发者 https://www.devze.com 2022-12-30 14:25 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 5 years ago.

Improve this question

Well I know basic Java and wanted to learn Swing so of course looked at the Sun website first, where this tutorial is. I was going to start it开发者_运维问答 but realised it relied heavily on NetBeans, which I'm not sure about.

I'm not sure because it's learning that I want to acheive, not a nice looking program.

So I thought using NetBeans like this would be great once I know it, but I don't want to be building things without a clue what's going on underneath, and of course this could also cause problems later.

My first question is is this the right way to do it, should I try not to rely on an IDE heavily? Looking through questions on the site most people recommend using the Sun tutorial, and I've only seen one answer that agrees with what I'm thinking, and they linked to this resource which looks promising. Or perhaps I'm getting the wrong idea of the Sun tutorial, perhaps it doesn't rely on the IDE, it just seemed like that.

My second question is, if you agree with me, what resources (apart from the one above) would you recommend?

Thanks for your answers.


I wouldn't say that Sun relies on NetBeans in their tutorials as much as references NetBeans because NetBeans is Sun's IDE.

I use Eclipse for my Java development. A good IDE can help you with the busy work, so you can focus on the problem at hand.

If you want to learn Swing, I recommend The Definitive Guide to Java Swing, Third Edition. This book takes you step by step through layouts and widgets, using and reinforcing the MVC pattern of GUI development.

For the advanced Swing developers, I recommend Swing Hacks: Tips and Tools for Killer GUIs. This book shows you some tricks to make your GUI pop.


The tutorial predominantly is about code. It's really just the one chapter on NetBeans. The rest of it is about Swing and can be done in any IDE.

I would not recommend working with a GUI builder, simply because as you say, you don't get to understand what's going on underneath. Start with simply windows and progressively work you way through adding GUI components and interacting with them. Understand the advantages of the MVC way of doing things.

And the best recommendation I can give is don't sit down to "Learn" Swing. Pick yourself out a project that interests you and you can do using Swing. By having a goal of a working program in mind, you will better absort the lessons that the tutorials give.


It seems you are a beginner in swings. I would recommend not to rely on Netbeans to develop swing UI. Try to design the UI by writing code only. This will improve your knowledge base on swings and then you can go using the GUI builder available if you so wish.


I've never found GUI builders to be very useful in Java anyway. NetBeans has a very good one, but I highly recommend you build your own GUIs.

On the other hand, you may find Swing GUis somewhat verbose. There are alternatives, Java-FX apparently has a declarative language that you can define your GUI in while writing everything else in Java.

Also Groovy has a nice declarative syntax layer over Swing that can make things a little easier when starting out.

If you want to experiment with Swing, I recommend playing with it in Groovy or BeanShell. It's a real quick to just type:

f=new JFrame("My Frame")
f.setVisible(true)
f.setSize(300,600)

and see your frame show up on the screen. (Both Groovy and Beanshell handle Java syntax very well--it's not like you are not learning Swing--it's more like you are learning it in an interpreter instead of compiler...

By the way, if you don't want to use Java's syntax Groovy can make it easer with statements that are SOMETHING like this (I may have it wrong by just a tad)

f=new JFrame(name="My Frame", visible=true, size=[300,600])

which changes it from 3 or 4 lines down to one.


I always learn new frameworks best the low-level-way.

  1. Learning a new programming language has proven to be the the best for me if I had to compile source files with the command line. Using an IDE like xCode makes it significant more hard to understand the basics.
  2. I had a very hard way of learning to understand basic concepts of the Eclipse platform, because nearly all tutorials just tell you were to click in the Eclipse GUI. No up-to-date tutorial told what lines to add to what XML file and how the things belong together. Fortunately, this was much simpler for Swing.

Hence my recommendation: don't use a GUI builder for learning, because it hides all the important things which help to really understand what's going on. Use a good Java/Swing tutorial and start typing your applications. After you understand the basics, you can use a GUI builder for prototyping.


Actually those tutorials do reference Netbeans multiple times but usually still tell you how to do stuff in code. Once you got a fairly good grasp of how Swing in general works you will likely read each of those when you need it.

For example Using Swing Components has (more or less) in-depth notes on each of the standard UI components and Laying Out Componnents has details about the standard layout managers.

Those are – at least for me – the things I return to the most. And exclusing a very brief touch with Netbeans I never touched its GUI builder again.


I think that you should learn the language first. Using an IDE makes you more efficient, however I think can lead to problems down the road should you need to use a different IDE. I find this book highly useful, Introduction to Java Programming. All the examples in the book are in code.

0

精彩评论

暂无评论...
验证码 换一张
取 消