when we have learned the basic syntax in Java, and familiar with the Java Object-oriented Foundation, we can start a simple swing program design, the use of VB Friends may be its simple design user interface approach to attract, just drag a few controls to the form, Writing an event for each empty piece can be a simple interface design. But the powerful Java is no better than VB? You can also design a beautiful interface.
2.Swing Overview:
when java1.0 just appeared without swing, when the GUI Basic programming library, Sun named AWT (Abstract Window tookit), the basic AWT library processes the user interface by handing the creation behavior of these elements to the The GUI toolbox of the underlying operating system is processed to realize the purpose of Wora. For a variety of reasons, there are differences between different OS, making the AWT interface inventory in many bugs. Sun worked with Netscape in 1996 to create a new library named swing.
------If, there is no Swing,java graphical interface penniless.------
Swing is the basic class of Java, is a part of JFC, complete JFC is very large, including a lot of components.
3. Why choose Swing:swing a richer and more convenient set of user interface elements, swing has less reliance on the underlying platform, so fewer bugs on special platforms will bring a unified visual experience on the cross platform
4. Many beginners Java friends after learning the basic part of Java will feel very dazed, or what Java can do is not very understanding, so in the initial grasp of the basic concept can be near a step of research swing, can be a certain improvement for beginners.
below we'll come to the preliminary study of a program that individuals feel is a good code for getting started swing.
frame.show (); To implement the close frame, but not the end of the program, its abort is just the main thread of the program,
Part II:
class Hellocsdnframe extends jframe{
public hellocsdnframe ()
{
settitle ("Hello csdn.net");
SetSize (Width,height);
hellocsdnpanel panel=new Hellocsdnpanel ();
Container C=getcontentpane ();
C.add (panel);
}
public static final int width=300;
public static final int height=200;
}
/**this Part We extend my hellocsdnfram to JFrame and
construct a new object Hellocsdnpanel and add it on the frame
/*
Here we take the object we created to the Java JFrame class, so that he has jframe attributes. Behavior. Then set the title and size, and create a new object again Hellocsdnpanel This is because it was implemented in JFrame, so to build container c. Put the Panel object we built into the CONTAINERC.
/Continue our inheritance of the newly established Hellocsdnpanel
to JPanel makes our objects have JPanel properties, and then we can invoke the method of outputting characters on the frame g.drawstring
This program on the one hand, we can see the core of Java thinking----inheritance relationship, on the other hand can see the basic structure of swing.
He has several layers, and each layer implements its own what function.
5. From this we can see the internal structure of the frame:
------JFrame (bottom)
|
---------Jroot
|
---------JLayeredPane
|
-----------Menu Bar
|
-----------Content Pane
|
-----------Transparent pane (top level)
and in these 6 layers we are most related to the menu bar and the content pane. Because it feels like our frame.
Summary: You can see that swing is a good Java performance, no wonder that the book on Swing can be written in a very thick, this chapter is only to teach those beginners, for Java has a better understanding, not near to stay in the console programming.
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.