Java Swing Components Full Demo

Source: Internet
Author: User

A piece of

This article refers to the use of a small program "Swing Component Encyclopedia" to guide you to learn the Java language, familiar with the various components of Java Swing. In the course of learning, the author designs The method and thought of the program, and finally forms his own way of thinking and learning. It is the author's happiest thing to give you a return of three. The applet demonstrates most of the components of Java swing. Finally, all the code and detailed explanatory notes are attached. I hope this article can help you learn java.

With the Java craze sweeping the country, learning Java methods and paths more and more. And in a large number of books before, in the Java Large Class library before the big people are a little disoriented feeling, is to learn J2ee,j2me or ... However, all these are more or less inseparable from J2SE. A towering high-rise rises from the ground. J2SE is the foundation of the whole Java, it is good to learn this to Java in every direction is very advantageous. The first point of learning J2SE is in the interface design, because the interface programming is you to feel the most direct means, is to improve everyone programming interest very good start, because you write the program after compiling can immediately see their results. And not like the background programming has done not feel the effect. A good interface is also the basis for testing your other programs.

Interface design! No, it's a drag-and-drop operation. If it is VB,VC and other visual programming, it is really just a drag operation, because the Java language design of all the things Are program code, in Java if you want to design a good interface, it is not a simple drag operation can be done. Even with the powerful visualization tools such as JBuilder, you have to write some interface design code yourself to do your job well. If you can understand the idea of Java interface design on this basis, it will be of great help for you to learn this language.

The Java interface design mainly involves the awt,swing two kinds of libraries, swing is the AWT extension and the function enhancement. Let's talk about the entire Java interface design based on swing.

Second feeling effect

Before we begin, let's take a look at the effect of this article, with the goal and the results of learning interest, at least I think and learn. As the following illustration shows, this is the interface we designed, which includes most of the commonly used components of swing. Some of the features are not reflected in the interface, you can try to compile the source code point South hit the various parts to see their response events.

Three design ideas and methods

Do not know that everyone (usually beginners) in the reading of programming books have this experience does not: in the process of watching, as if a large understanding, and efficiency is good, but turn back to write a book and the same program out of books, may be a lot of people only to take a book shot, and some people in the book after the dozen, it seems to understand. Can turn back to the real use of the time, as if they do not remember. The author himself has experienced many times in the beginner's programming.

Chasing its reasons, there is no mastery of the knowledge, programming the most emphasis on the word, the real meaning of the action is to write their own understanding of the process rather than copy ready-made procedures. Because only through their own thinking, design can really dissolve the knowledge of the book into their own brains. Let's say this method and idea in the Swing component encyclopedia.

After reading the swing components introduced in the book, I probably had a good idea of swing in my mind. And I do not want to follow the example of a book to try. So I thought of doing a program to put all the components described in the book into an interface, and try to use all the methods described in the book.

Chopping wood does not mistake the sharpening work! Before I started, I drew a design drawing, as shown in the above interface (not so beautiful, of course). With simple software engineering thought, the structure is divided roughly. The whole interface is divided into one main module and five modules. All of the sub modules are inherited to the appropriate container, the main module swingtest is both a management module and the main interface, inheriting the JFrame main frame, managing its own attributes and other sub modules on the JFrame. The Menutest module inherits to JMenuBar to be responsible for menu display and event handling. Other child modules inherit to JPanel to manage the layout and display of the components placed on them. From the name of the child module you can also see their location and function. As shown in the following illustration:

 

It's a good habit to think about the structure and ideas before you write a program, which will help you reduce your workload and improve the readability and efficiency of your program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.