开发者

How can I create a GUI in Java using only code and not the graphical drag and drop? [uber-newbie]

开发者 https://www.devze.com 2022-12-17 11:07 出处:网络
I\'ve been told that creating GUI\'s using drag and drop generates unnecesary code and is frowned upon by most Java developers.

I've been told that creating GUI's using drag and drop generates unnecesary code and is frowned upon by most Java developers.

I'm used to dragging and dropping things using Windows Forms **but ** I'm also very comfortable creating things using XAML for WPF applications.

I'm a bit lost however on how to create a ba开发者_JS百科sic GUI in Java using only code.

What I'm using: Netbeans 6.8

What I want to do: Create a simple Window that will act as the main one that opens up when the application launches.

How can I create a simple Window with the standard window buttons (close, minimize, maximize) and have a little button on the middle of it. Using only code.

Also, what type of project do I create using NetBeans?

Thanks for the help.


I feel like this kind of question is best answered with a link to a tutorial, so here you go:

From java.sun.com, Trail: Creating a GUI With JFC/Swing


The link provided by danben is really helpful. If you really want to lay out everything from scratch, then you have to be able to answer such questions as

  • What is container? Which components are containers?
  • How components are positisioned within a container (layout manager)?

The link provided will give you the answer.


I heard that one before. I don't know what is with java developers and always insisting that you have to write the gui by code and can't use drag and drop tools. For me I don't care if it generates unnecessary code. I personally don't think it will make that much of a difference.

The only thing I would never recommend is using a designer for websites since they usually never look the way you designed it when you actually test it on a browser but for windows GUI just use a designer.

I look at it this way. There might be a bit more of unnecessary code but your bosses won't care about that. They will be more concerned why your taking so much longer on something and costing the company so much more money on little to no effect to the final product.

To answer your question you probably can pick up any book from java and they will have tutorials on how to make GUI's by code.


To do it programatically, you have to be able to understand code in general. As far as I know Java does not have a simple XML based layout language for GUI-s. So first you have to learn how to program. (But you can try JavaFX's script language, might be easier to master first.) You can easily learn your way in the simple cases from the generated code, then continue using swing javadoc and google.

GUI builders are handful, nevertheless. It is a plausible that once you are required to mock up a GUI layout as a prototype, tracer bullet, presentation material etc. Generated code might be even completely irrelevant.

0

精彩评论

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