Java Interface Development

Source: Internet
Author: User

java.awt no cross-platform javax.swing with cross-platform all classes start with J

JButton is the form in javax.swing corresponding to java.awt in the form of a button

Elements of the interface (found in the API documentation):

Top-level container (form) javax.swing.JFrame

Text, picture label Javax.swing.JLabel

Text input Box Javax.swing.JTextField

Password input Box Javax.swing.JPasswordField

check box (tick) Javax.swing.JCheckBox

Button Javax.swing.JButton

Picture Javax.swing.ImageIcon

Text javax.swing.String

Size Java.awt.Dimension

Flow layout Java.awt.FlowLayout (an element then an element is arranged downward, if one line is not enough to move to the next line, so by adjusting the length to be the same element alignment)

Steps to do the interface: Create an interface class and define a method for the login interface

To create a form:

Javax.swing.JFrame frame=new javax.swing.JFrame ();
Frame.settitle ("QQ login");
Frame.setsize (400,400);
Frame.setlocationrelativeto (NULL); ......... Center position (position)
Frame.setdefaultcloseoperation (Jframe.exit_on_close); ........... Click x to close all [several close several]

Dispose_on_close ..... Click X to close the corresponding one [other not off]

Do_nothing_on_close ..... Dot x doesn't have any effect

Set the layout of the form to flow layout: Java.awt.FlowLayout flow=new java.awt.FlowLayout ();
Frame.setlayout (flow);

Insert Picture label: Javax.swing.ImageIcon icon=new Javax.swing.ImageIcon (GetClass (). GetResource ("title.jpg"));

Javax.swing.JLabel iconlabel=new Javax.swing.JLabel (icon);

Iconlabel.setpreferredsize (New Java.awt.Dimension (400,200));

Frame.add (IconLabel);

Insert User name tag: Javax.swing.JLabel usernamelabel=new javax.swing.JLabel ("User name");

Usernamelabel.setpreferredsize (New Java.awt.Dimension (80,25));

Frame.add (Usernamelabel);

Insert User name Input box: Javax.swing.JTextField usernametext=new Javax.swing.JTextField ();

Usernametext.setpreferredsize (New Java.awt.Dimension (280,25));

Frame.add (Usernametext);

Or:

Javax.swing.JTextField usernametext=new Javax.swing.JTextField ();
Java.awt.Dimension untextsize=new java.awt.Dimension (280,25);
Usernametext.setpreferredsize (untextsize);
Frame.add (Usernametext);

Java Interface Development

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.