Buttons for the Java user interface

Source: Internet
Author: User

A simple component that can be added to a container is a JButton object, and the JButton object is a button that can be clicked

Create JButton Component : JButton button = new JButton ("button");

Call the Add () method to add it to the container : Add (Button);

When adding components to a container, you do not need to indicate where the component is located in the container, the layout of the component is determined by the layout manager , and the simplest layout manager is the FlowLayout class

  Create FlowLayout Object : FlowLayout flo = new FlowLayout ();

  Call the SetLayout () method to associate the container with the manager : setlayout (FLO);

Demo:

1  PackageCom.swingdemo.demo;2 3 Importjava.awt.FlowLayout;4 5 ImportJavax.swing.JButton;6 ImportJavax.swing.JFrame;7 ImportJavax.swing.UIManager;8 Importjavax.swing.UnsupportedLookAndFeelException;9 Ten  Public classPlaybackextendsJFrame { One  A     Private Static Final LongSerialversionuid = 1L; -      -      PublicPlayback () { the  -         Super("Playback"); - Setlookandfeel (); -SetSize (225, 80); + setdefaultcloseoperation (jframe.exit_on_close); -FlowLayout Flo =NewFlowLayout (); + setlayout (flo); AJButton play =NewJButton ("Play"); atJButton stop =NewJButton ("Stop"); -JButton pause =NewJButton ("Pause"); - Add (play); - Add (stop); - Add (pause); -SetVisible (true); in      -     } to      +     Private voidSetlookandfeel () { -  the         Try { *Uimanager.setlookandfeel ("Com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); $}Catch(Exception e) {Panax Notoginseng e.printstacktrace (); -         } the     } +  A      Public Static voidMain (string[] args) { the          +Playback PB =NewPlayback (); -          $     } $  -}
View Code

Buttons for the Java user interface

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.