Java Swing First Hello Word

Source: Internet
Author: User

Let's start with a Java swing Helloword program.

1  Packagecn.java.swing.chapter03;2 3 ImportJavax.swing.JButton;4 ImportJavax.swing.JFrame;5 ImportJavax.swing.JPanel;6 7  Public classDemo01 {8 9      Public Static voidMain (string[] args) {TenJFrame JFrame =NewJFrame ("Chapter03 Demo1");//creating a top-level container One          AJPanel JPanel =NewJPanel ();//Creating intermediate containers -          -Jframe.setcontentpane (JPanel);//The intermediate container is supported in the top-level container the          -JButton button =NewJButton ("one Test button");//Create a basic component -          -Jpanel.add (button);//base components are built into intermediate containers +          -          +Jframe.setsize (200,300);//set top level container size A          atJframe.setvisible (true);//Show Top level components -          -     } -}
View Code

Swing is roughly divided into three elements: top-level containers (JFrame), intermediate containers (JPanel), basic components (Button, Label)

Intermediate containers and basic components need to be placed in the top-level container before they are valid.

There are mainly three top-level containers in swing
1.JFrame is designed to design applications similar to Windows systems in the form of Windows
2.JDialog is similar to JFrame, except that JDialog is used to design dialog boxes
3.JApplet Java applet designed for embedding into web pages

Pending additions

Java Swing First Hello Word

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.