Java make button

Source: Internet
Author: User

Making a button is simple: just call the button builder and specify the label you want to appear on the button (if you don't want the tag, you can use the default builder, but that rarely happens). You can refer to a later program to create a handle to the button so that you can reference it later.
A button is a component that, like its own small window, is redrawn when it is updated. This means that we do not have to explicitly depict a button or any other kind of control; just incorporate them into the form, and later work on them will be the responsibility of their own. So in order to place a button into a form, you need to overload the Init () method instead of overloading paint ():

: Button1.java
//putting buttons on a applet
import java.awt.*;
Import java.applet.*;

public class Button1 extends Applet {
  button 
    B1 = New button ("button 1"), 
    b2 = New button ("button 2");
  public void init () {
    Add (B1);
    Add (b2);
  }
///:~

However, this is not enough to create a button (or any other control). You must also call the Applet Add () method to place the button in the form of the program slice. This may seem a lot simpler than it really is, because calls to add () actually decide where to place the control on the form. The controls on the layout of the form are immediately mentioned.

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.