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