Making a Java button

Source: Internet
Author: User

Swing adds some different types of buttons, and it can also modify the structure of the selected component: All buttons, check boxes, radio buttons, even menu items inherited from AbstractButton (this is because the menu item is generally included in it, it may be improved by naming " Abstractchooser "or the same name). We will pay attention to the simplicity of using menu items, and the following examples show different types of available buttons:
 

//: Buttons.java//Various Swing Buttons package c13.swing; import java.awt.*; import java.awt.event.*; import Java
x.swing.*;
Import javax.swing.plaf.basic.*;

Import javax.swing.border.*;
  public class Buttons extends JPanel {JButton jb = new JButton ("JButton"); Basicarrowbutton up = new Basicarrowbutton (Basicarrowbutton.north), down = new Basicarrowbutton (basi
      Carrowbutton.south), right = new Basicarrowbutton (basicarrowbutton.east), left = new Basicarrowbutton (
  Basicarrowbutton.west);
    Public Buttons () {Add (JB);
    Add (New Jtogglebutton ("Jtogglebutton"));
    Add (New Jcheckbox ("Jcheckbox"));
    Add (New Jradiobutton ("Jradiobutton"));
    JPanel JP = new JPanel ();
    Jp.setborder (New Titledborder ("directions"));
    Jp.add (UP);
    Jp.add (down);
    Jp.add (left);
    Jp.add (right);
  Add (JP);
  public static void Main (String args[]) {show.inframe (New Buttons (), 300, 200); }
} ///:~

JButton looks like the AWT button, but it has no more functions to run (such as adding images as we'll see later). In Com.sun.java.swing.basic, there's a more appropriate Basicarrowbutton button, but how do you test it? There are two types of "pointers" that just request the arrow buttons to use: Spinner modifies an interrupt value, and Stringspinner moves through an array of strings (it is even automatically encapsulated when it reaches the bottom of the array). Actionlisteners attaches to the arrow buttons to show the related pointers it uses: because they are beans, we expect to capture and set their values just by using the method name.
When we run this program example, we find that the trigger button keeps its current state, on or off. But check boxes and radio buttons are the same for each action, checked or unchecked (they inherit from Jtogglebutton).

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.