Java GUI programming (swing) two swing button components

Source: Internet
Author: User

Swing's button component. In the Widgets class. To use a button, you must import Jbuttonimport Javax.swing.JButton; the button needs to be added to the Frame inside the package Gui;import Java.awt.frame;import Javax.swing.jframe;import javax.swing.jbutton;/*** Created by admin on 2017/6/30.* Java GUI learning */public class GUI extends J Frame{jbutton JButton = null;public static void Main (string[] args) {gui GUI = new Gui ();} Constructor public Gui () {///JFrame is a top-level container class that can add other swing components//JFrame JFrame = new JFrame (); JButton = new JButton ("button 1");//Set form title T His.settitle ("Hello world!"); /Set the form width and height, in pixels, rather than the centimeter this.setsize (350, 200) that we normally understand;//The added component is usually after the frame size is set// Add a component (button) if there is no layout then the entire button will occupy the Framethis.add (JButton),//Display the form this.setname ("app");//Set the position of the form this.setlocation (500, 250)///Set exit window when JVM virtual machine also exits this.setdefaultcloseoperation (jframe.exit_on_close); this.setvisible (true); }}

Java GUI programming (swing) two swing button components

Related Article

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.