JFrameto view the window is

It – Hardware & Software | | 1 views

Swing and AWT

You remembered the basis of Java temporarily.It reached the point where it can make also the program which used the window with AWT.Well, the following step probably is what n/a So the person who is thought.Perhaps it is the expectation which is several choices before you.

As for one, road to of server side Java.
As for one, road to of carrying such as i application Java.
As for one which remains, rather than depending on Swing, the road to high-level GUI application.

More real application will be drawn up, that the road where the person who is thought should advance probably will be “the road to Swing”.If Swing is used, it is possible to utilize higher-level GUI than AWT much.With this serialization, for the person who aims toward more real application development, it keeps explaining concerning the method of using Swing.

First, “Swing what ones?” the empty it will keep explaining.In the first place, the GUI kit, AWT from beginning was loaded in Java.That, ver. 1.2 It is the case that it is decided that the framework, Swing empty and anew is added.Why, it probably is to prepare Swing other than AWT.Are both probably to be some kind of difference?and to organize, will be as follows:.

Swingapplication by. normalWindowsthe look and feel similar to that of, be seen that the slightly different.

-AWTisOSas it is the look and feel of
AWTwas created inGUIis, thatOSremain the same look and feel of. is, Swingthat are created inGUIis, OSthose that are specific to a slightly different feel, has become a unique atmosphere. OSyou can also match the look and feel of, is not exactly the same, law and is a good idea.

-AWTcontains the native code
AWTis, relies on many parts of its native code. for exampleButtonwhen you create a, internallyOSofAPIi have it to display the button on the screen or call the drawing function of the buttons on the. Javainstead ofOSi have been drawing a faster speed, etc. by the use of a feature in the, in reverseJavabecause we can not control the display portion is, no longer can customize the display of the button. the more degrees of freedom is low.

· the difference between the operating speed
Swingis, AWTit has extended based on the, basicallypure Javaare moving in. for this reason, AWTsuch that the display has become a feel or have a little more will not be denied. but, allJavais that it can be, you can freely customize the display as well as. it is that much higher degrees of freedom.

-the difference between the level of standard components
AWTcomponent, which comes standard with the, generalGUIonly the basic ones used in the. compared to this, Swingcomponents that are mounted on is a wide range of. AWTtree view has not been provided, sheet of the spreadsheet, slider, such as spinning a lot of buttonGUIthe component is provided for. also, Swingclass component of the, has a separate class of data structures and to perform and display of, it is also possible to change the behavior of the component, such as by creating them with the new.

· differences in display capabilities
AWTcomponent of the, basically tweak the display can not be. is, as mentioned earlierSwingyou can freely change the display in. it not only, also look and feel of the components, provides a set of several, Windowswind, Linuxyou can change and so the wind can be. a mechanism to draw the component alsoAWThas become much more complicated, has to be able to control fine.

——or more, if you organize, it can not be advanced but simple and easy to useAWT and complex and difficult to master but it can be more sophisticated representationSwing what is the difference between a good idea to say that.

recently, of client sideGUIlet’s reconsider the development the movement has been strengthened. so farJavaof the world, has been moved to center the evolution of server-side rather. is, recently users will use more directGUIit is necessary to consider the part is changing and so on. the world of the internet, RIA(Rich Internet Application) called, more sophisticatedGUIthere are internet applications that have attracted the attention. easilyRIAcan be realizedJavathe applet, are being re-evaluated recently.

at the heart that is, Swingis a. Swingreview, trying to take advantage of more. for example, the nextJava 7a new scripting language that is said to be equipped with standard Java FX such as is, with a simple scriptGUIthe thinking is designed to build a, being available to this, yappariSwingis a.

in, immediatelySwinglet’s use the>>

JFramebasic code using the

so, in factSwinglet’s try using. SwingisAWTand another isGUIit is a framework, but the basic partsAWTquite similar. AWTin, if you want to create applications that use the common window, Framewe have defined a class that inherits from the class.

Swingthis is similar to but. but, class name that is provided isFrameinstead of JFrame will be. in, let’s create a window display program very rudimentary. here, jp.allabout.javain a package called SampleApp try to create a class named.

package jp.allabout.java;

import java.awt.*;
import javax.swing.*;

public class SampleApp extends JFrame {
private static final long serialVersionUID = 1L;

public SampleApp(){
this.setSize(new Dimension(300,200));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
new SampleApp().setVisible(true);
}
}

window is1sheet, which appears only. this is, Swingi window.

it is very simple. simply, the window there is nothing1are only displayed on the screen images. the program will exit by clicking the close box in the window as it is. i say is not even sample, in the sample from this shortSwingthe underlying knowledge can grasp some of the most.

-Swingcomponent of the, javax.swingpackage!
AWTif the, class componentjava.awtwere grouped into packages. Swingin the case of the, javax.swingwill be in a package called.

· the component name J is attached!
here, JFrame took advantage of a component called. this is, AWTis used to display the window Frame ofSwingyou may want to say version. Swingalso, AWTprovides you with almost the same as class components had been prepared to. but, because i become confused when the same class name, Swingside at the beginning of the class name J you with a. FrameifJFrame, ButtonifJButtonand so on.

-JFramethe standard treatment is a closed box
here, Swingprocess-specific1only the rows that have been written. setDefaultCloseOperation is a method called. this isJFramethose that are provided by the, which specifies how to handle when you try to close the window by clicking the close box. this is, JFramespecifies the class field that are provided by the

here, JFrame.EXIT_ON_CLOSEit has set something called. this is, to exit the program as it is to close the window, demonstrates how a process called. by setting this, program i was supposed to end if you click the close box. AWTas, ichiichiWindowListenerit’s that easy compared with a great deal you will need to be incorporated into the.

let’s built-in components followed by>>

incorporate a component

in, let’s incorporate the unique component followed by. as the most basic component, label, input field, try to place each of the push button.

package jp.allabout.java;

import java.awt.*;
import javax.swing.*;

public class SampleApp extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel label;
private JTextField field;
private JButton button;

public SampleApp(){
this.setSize(new Dimension(300,150));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label = new JLabel(“This is Sample.”);
label.setFont(new Font(“Serif”,Font.BOLD,24));
this.add(label,BorderLayout.NORTH);
field = new JTextField();
this.add(field,BorderLayout.CENTER);
button = new JButton(“click”);
this.add(button,BorderLayout.SOUTH);
}

public static void main(String[] args) {
new SampleApp().setVisible(true);
}
}

incorporating the componentSwingwindow of.

here you are using, each JLabel JTextField JButton is a component called. alreadyAWTif you’re using the, the basic usage is almost the same thing will find. eachnewcreate an instance of a, addinJFrameit is incorporated in the. also, incorporate as a position, BorderLayout.NORTHsoBorderLayoutyou have specified a class field of. that is? JFramethe standard alsoBorderLayouti have built is that. also, JLabelto set the display font, Fontprovides an instance of the class, setFonthas been.

as you can see from these things, SwingbutAWTyou can use many features of are carried over intact. to tell the truth, Swingcomponent of the, AWTit has been created to inherit the components of the. so, and layout managers, for the fontFontclass, to specify the color orColorclasses, etc., many classesAWTit is common at all.

this code, and in fact more correctly write? >>

and the content pane?

in those who read this article while moving the sample actually, the previous sample does not work! some people may not. in fact, the previous sample is, Java 5writing is a later. how to write the original, be the same again a little more. in, from the previous list, let’s rewrite an excerpt only a portion of the constructor.

public SampleApp(){
this.setSize(new Dimension(300,150));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container contentPane = this.getContentPane(); /
label = new JLabel(“This is Sample.”);
label.setFont(new Font(“Serif”,Font.BOLD,24));
contentPane.add(label,BorderLayout.NORTH);
field = new JTextField();
contentPane.add(field,BorderLayout.CENTER);
button = new JButton(“click”);
contentPane.add(button,BorderLayout.SOUTH);
}

this is, Swingis writing the original. part of the getContentPane call a method called, Containeri have taken out an instance. and, after you create a component class, thisContainertoaddhas been. JFrameto directlyaddhas not been. on earth, what do you mean this is probably the?

thisgetContentPaneobtained byContaineris, content pane this is called. Swingrelationship in the class of the window, has the structure of the transparent layer is overlapped on top of the window some. layer to place the component, menu layer is placed between, layer and so on, such as a mouse pointer is displayed, i have a form of superposition of several layers of transparency depending on the application.

each layer, is a containerContainerhas been implemented as an instance of the class. and, thisContainerto, is not going to configure the display incorporates a variety of objects, if necessary.

if you place a component on a window, some kind in the component layer will be placed content pane place the. it should not be incorporated directly into the body window. there, as mentioned above or strikegetContentPanegets an instance of the content pane is, in contrastaddit i had been.

in, Java 5subsequent, why directaddyou can? it is no longer content pane? ——ieie, is not the case. Java 5even after, structure of the content pane is intact. the only difference is built-in method has increased is that.

integration into the content pane, principle, but as you know, AWTto be more troublesome is no different. there, Java 5from JFramedirectly to theaddthen, let it be automatically incorporated into the content pane! i have been fixed and features. for this reason, JFramedirectly to theaddi did not incorporate the.

having said, this is only also incorporate the content pane to do so that there is, component is incorporated into all content pane structure that does not change. please understand this point is firmly.