学习Java Swing(GUI构建器与否?)

时间:2023-01-27 13:14:10

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.

我知道基本的Java,并且想学习Swing,所以当然首先看看Sun网站,本教程是在哪里。我打算开始它,但意识到它严重依赖NetBeans,我不确定。

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.

所以我认为一旦我知道它就会使用像这样的NetBeans,但我不想在没有线索的情况下构建一些东西,当然这也可能在以后引起问题。

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.

我的第一个问题是这是正确的方法,我应该尽量不依赖IDE吗?通过网站上的问题查看大多数人建议使用Sun教程,我只看到一个与我正在思考的内容相符的答案,并且他们将这个资源与看起来很有希望的资源相关联。或者我可能对Sun教程有了错误的想法,也许它不依赖于IDE,它就像是这样。

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

我的第二个问题是,如果你同意我的话,你会推荐哪些资源(除了上面的资源)?

Thanks for your answers.

谢谢你的回答。

7 个解决方案

#1


7  

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

我不会说Sun在他们的教程中依赖NetBeans,就像参考NetBeans一样,因为NetBeans是Sun的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.

我使用Eclipse进行Java开发。一个好的IDE可以帮助您完成繁忙的工作,因此您可以专注于手头的问题。

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.

如果你想学习Swing,我推荐Java Swing的权威指南,第三版。本书将逐步介绍布局和小部件,使用和强化GUI开发的MVC模式。

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.

对于高级Swing开发人员,我推荐Swing Hacks:Killer GUI的提示和工具。本书向您展示了一些使您的GUI流行的技巧。

#2


1  

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.

该教程主要是关于代码。它实际上只是关于NetBeans的一章。其余部分是关于Swing的,可以在任何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.

我不建议使用GUI构建器,只是因为正如您所说,您无法理解下面发生了什么。从简单的窗口开始,逐步添加GUI组件并与它们进行交互。了解MVC做事方式的优点。

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.

我能给出的最佳建议是不要坐下来“学习”Swing。选择一个你感兴趣的项目,你可以使用Swing。通过记住工作计划的目标,您将更好地摒弃教程提供的课程。

#3


1  

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.

看来你是秋千的初学者。我建议不要依赖Netbeans来开发swing UI。尝试仅通过编写代码来设计UI。这将提高您对秋千的知识基础,然后您可以根据需要使用GUI构建器。

#4


1  

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.

我从来没有发现GUI构建器在Java中非常有用。 NetBeans非常好,但我强烈建议您构建自己的GUI。

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.

另一方面,你可能会发现Swing GUis有点冗长。还有其他选择,Java-FX显然有一种声明性语言,您可以在用Java编写其他所有内容时定义GUI。

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

此外,Groovy在Swing上有一个很好的声明性语法层,可以让你在开始时更容易一些。

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

如果你想试验Swing,我建议在Groovy或BeanShell中使用它。只需输入即可快速输入:

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...

并看到你的框架出现在屏幕上。 (Groovy和Beanshell都能很好地处理Java语法 - 它不像你没有学习Swing - 它更像是你在解释器而不是编译器中学习它...

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)

顺便说一句,如果你不想使用Java的语法,那么Groovy就可以使这样的语句变得更加容易(我可能只是一点点就错了)

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

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

它将它从3行或4行更改为1。

#5


1  

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. 如果我不得不使用命令行编译源文件,那么学习一种新的编程语言对我来说是最好的。使用像xCode这样的IDE会使理解基础变得更加困难。
  3. 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.
  4. 我有一种很难学习理解Eclipse平台基本概念的方法,因为几乎所有的教程都告诉你要点击Eclipse GUI。没有最新的教程告诉哪些行添加到XML文件以及这些内容如何组合在一起。幸运的是,这对于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.

因此我的建议是:不要使用GUI构建器进行学习,因为它隐藏了所有有助于真正了解正在发生的事情的重要事项。使用优秀的Java / Swing教程并开始键入您的应用程序。了解基础知识后,可以使用GUI构建器进行原型设计。

#6


0  

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.

实际上,这些教程确实多次引用Netbeans,但通常仍然会告诉您如何在代码中执行操作。一旦你掌握了Swing的一般工作方式,你就可以在需要时阅读每一个。

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.

例如,使用Swing Components对每个标准UI组件都有(或多或少)深入的注释,Laying Out Componnents包含有关标准布局管理器的详细信息。

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.

那些 - 至少对我而言 - 是我回归最多的事情。并且与Netbeans进行了非常简短的联系,我再也没有触及过它的GUI构建器。

#7


0  

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.

我认为你应该先学习这门语言。使用IDE可以提高效率,但是如果您需要使用其他IDE,我认为可能会导致出现问题。我觉得这本书非常有用,Java编程简介。书中的所有例子都是代码。

#1


7  

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

我不会说Sun在他们的教程中依赖NetBeans,就像参考NetBeans一样,因为NetBeans是Sun的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.

我使用Eclipse进行Java开发。一个好的IDE可以帮助您完成繁忙的工作,因此您可以专注于手头的问题。

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.

如果你想学习Swing,我推荐Java Swing的权威指南,第三版。本书将逐步介绍布局和小部件,使用和强化GUI开发的MVC模式。

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.

对于高级Swing开发人员,我推荐Swing Hacks:Killer GUI的提示和工具。本书向您展示了一些使您的GUI流行的技巧。

#2


1  

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.

该教程主要是关于代码。它实际上只是关于NetBeans的一章。其余部分是关于Swing的,可以在任何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.

我不建议使用GUI构建器,只是因为正如您所说,您无法理解下面发生了什么。从简单的窗口开始,逐步添加GUI组件并与它们进行交互。了解MVC做事方式的优点。

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.

我能给出的最佳建议是不要坐下来“学习”Swing。选择一个你感兴趣的项目,你可以使用Swing。通过记住工作计划的目标,您将更好地摒弃教程提供的课程。

#3


1  

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.

看来你是秋千的初学者。我建议不要依赖Netbeans来开发swing UI。尝试仅通过编写代码来设计UI。这将提高您对秋千的知识基础,然后您可以根据需要使用GUI构建器。

#4


1  

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.

我从来没有发现GUI构建器在Java中非常有用。 NetBeans非常好,但我强烈建议您构建自己的GUI。

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.

另一方面,你可能会发现Swing GUis有点冗长。还有其他选择,Java-FX显然有一种声明性语言,您可以在用Java编写其他所有内容时定义GUI。

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

此外,Groovy在Swing上有一个很好的声明性语法层,可以让你在开始时更容易一些。

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

如果你想试验Swing,我建议在Groovy或BeanShell中使用它。只需输入即可快速输入:

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...

并看到你的框架出现在屏幕上。 (Groovy和Beanshell都能很好地处理Java语法 - 它不像你没有学习Swing - 它更像是你在解释器而不是编译器中学习它...

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)

顺便说一句,如果你不想使用Java的语法,那么Groovy就可以使这样的语句变得更加容易(我可能只是一点点就错了)

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

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

它将它从3行或4行更改为1。

#5


1  

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. 如果我不得不使用命令行编译源文件,那么学习一种新的编程语言对我来说是最好的。使用像xCode这样的IDE会使理解基础变得更加困难。
  3. 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.
  4. 我有一种很难学习理解Eclipse平台基本概念的方法,因为几乎所有的教程都告诉你要点击Eclipse GUI。没有最新的教程告诉哪些行添加到XML文件以及这些内容如何组合在一起。幸运的是,这对于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.

因此我的建议是:不要使用GUI构建器进行学习,因为它隐藏了所有有助于真正了解正在发生的事情的重要事项。使用优秀的Java / Swing教程并开始键入您的应用程序。了解基础知识后,可以使用GUI构建器进行原型设计。

#6


0  

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.

实际上,这些教程确实多次引用Netbeans,但通常仍然会告诉您如何在代码中执行操作。一旦你掌握了Swing的一般工作方式,你就可以在需要时阅读每一个。

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.

例如,使用Swing Components对每个标准UI组件都有(或多或少)深入的注释,Laying Out Componnents包含有关标准布局管理器的详细信息。

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.

那些 - 至少对我而言 - 是我回归最多的事情。并且与Netbeans进行了非常简短的联系,我再也没有触及过它的GUI构建器。

#7


0  

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.

我认为你应该先学习这门语言。使用IDE可以提高效率,但是如果您需要使用其他IDE,我认为可能会导致出现问题。我觉得这本书非常有用,Java编程简介。书中的所有例子都是代码。