JavaSE advanced GUI programming, javasegui

Source: Internet
Author: User

JavaSE advanced GUI programming, javasegui

The following mainly uses swing in java for interface design. Of course, the java GUI is not as good as the C # design, but the principle still needs to be met.

1. GUI Graphical User Interface GUI

A) It mainly includes the menu bar, window, toolbar, And button;

B) Java provides two GUI development packages: java. awt and java. swing. The Component abstract class in java. awt is the parent class of all classes in javaGUI. It specifies the basic features of all GUI components. j ava. swing is built on the basis of java. awt and introduces many new functions and features.

C) GUI Components

I. basic components: the widgets cannot contain other components, such as buttons and text boxes.

Ii. Container: You can add other components on it, such as Windows and dialog boxes;

 

 

2. Swing containers and components

A) create a top-level container (window implementation) ------ use of JFrame class

I. instance: JFrame frame = new JFrame (String title );

Ii. setLocation (int x, int y) set the display position of the form

Iii. setSize (int width, int height) set the size of the form

Iv. setVisible (Boolean B) set whether the form is visible

V. Obtain the content panel: Container con = fram. getContentPane (); add components on the Content panel

 

B) Basic Component Classification

I. text input component: JTextField --- text box JPasswordField --- Password box JTextArea --- text field JLabel --- label

Ii. Button component: JButton --- common button JCheckBox --- check box JRadioButton-single-sheet JComboBox-drop-down list box

 

C) common methods in JTextField

I. instantiation: JTextField text = new JTextField (int columns );

Ii. Public String getText () Get the content of the text box

Iii. Public void setTest (String text) set the content of the text box

 

D) JTextArea long-term method 4

I. instantiation: JTextArea area = new JTextArea (int rows, int columns );

Ii. Public String getText () Get Text domain content

Iii. Public void setText (String Text) set content in the Text field

Iv. Public void append (String Text) append content

// Add the text field JTextArea area = new JTextArea (); // set the text area. setText ("adfa"); // Append content area. append ("1345"); area. append ("543254 ");

V. con. add (area );

 

E) check box of JCheckBox

I. instantiation: JCheckBox check = new JCheckBox (String title, Boolean selected );

1 // add check box 2 3 JCheckBox check = new JCheckBox ("male", true); 4 5 con. add (check );

Ii. con. add (button );

F) JRadioButton

I. instantiation: JRadioButton radio = new JRadioButton (String titile, Boolean Selected );

G) Use of the ButtonGroup button group

I. instantiation: ButtonGroup bg = new ButtonGroup ();

Ii. Add the buttons in the same group to bg.

Iii. Add each button to the Frame.

1 // Add single-choice button group 2 3 ButtonGroup g = new ButtonGroup (); 4 5 JRadioButton radio0 = new JRadioButton ("Radio1 "); 6 7 JRadioButton radio1 = new JRadioButton ("Radio2"); 8 9g. add (radio1); 10 11g. add (radio0); 12 13 con. add (radio1); 14 15 con. add (radio0); 16 17 18 19 // add single-choice buttons for different groups 20 21 JRadioButton radio3 = new JRadioButton ("Radio3 ");

Iv. con. add (radio3 );

H) JComboBox drop-down menu

I. instantiation: JComboBox cb = new JComboBox (Object [] item );

 1         con.add(cb);

I) The JPanel class is the simplest container class that can accommodate all kinds of basic components, including other panels.

I. JPanel can be added to the form as a panel component.

1. Jframe. getContentPane. add (JPanel p );

2. Jframe. setContentPane (JPanel p );

// Add the Panel JPanel p = new JPanel (); // add it to the form con. add (p); // add content to p

 

3. p. add (radio3 );

4. p = new JPanel (LayoutManager layout );


Is GUI important for basic learning of javase?

I personally feel that it is useless, because now there is basically no java development interface, because its development interface is not very nice, java is now used in the network, for example, servlet ...........
-----------------------------------------------------------------
The high interface usually uses WPF and Objective-C. The former is for windows and the latter is for Apple. Although WPF and Objective-C cannot be cross-platform, from the current trend, the interface is completely not cross-platform, so if you want to specialize in GUI, you can take a look at the two.
----------------------------------------------------------------
[Note] mainstream java Development has started to favor javaEE for a long time. Now, even more, each language has its mainstream application fields, for example, java -----> network programming C/Cpp ----------> 3D animation/large game Objective-C --------> Apple's everything (of course, Objective-C is mostly responsible for Mac or ios interface, apple's advanced programming relies on C and Cpp)
-----------------------------------------------------------------
Can I skip what you said? Let me give you a simple answer.
(1) If you have never touched any GUI in the past, do not skip this step because java is simple and java's GUI architecture is simple, to understand the GUI from the java GUI, it is clear that the idea of writing the GUI is very different from that of writing the terminal. If you have never written the GUI, you must learn it, the above is not important, but it is for work, because no one is writing interfaces in java, but you cannot skip the idea of developing a GUI, this idea will broaden the thinking of people who always write terminal programs .............
(2) If you used to understand GUI and have written GUI, such as CPP or whatever language (except VFox and access), skip this java GUI.

Q: How can I learn eclipse GUI programming?

Java GUI programming? In fact, GUI is not the focus of JAVA. You can see that several software are written using java gui. Although JAVA is powerful, it is still not widely used in desktop programs. JAVA is mainly used in later J2EE. The GUI is actually very simple. It is simpler to have the foundation of web design. First, learn some common controls and view their construction methods and common methods. Then, let's look at the layout; the next step is event processing, mouse and keyboard events, etc. Understanding and using listeners. Make a little thing on your own. What about the calculator and notepad?

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.