Example of jlabel and jbutton-Event Response principles

Source: Internet
Author: User

/***//**
* @ (#) C10_1.java
*
*
* @ Author
* @ Version 1.00
*/

Import java. AWT .*;
Import javax. Swing .*;
Import java. AWT. event .*;

Public class c10_1 extends japplet implements actionlistener ...{
Container CP = getcontentpane ();
Icon Pa = new imageicon ("G:/javadocs/a1.gif ");
Icon Pb = new imageicon ("G:/javadocs/a2.gif ");
Icon Pc = new imageicon ("G:/javadocs/a3.gif ");
Jbutton bt = new jbutton ();
Icon Pd = new imageicon ("G:/javadocs/a4.gif ");
Jlabel lB = new jlabel ("hello", PD, jlabel. center );


/*** // *** Initialization method that will be called after the applet is loaded
* Into the browser.
*/
Public void Init ()...{
// Todo start asynchronous download of heavy resources
Bt. setroloverenabled (true );
Bt. settext ("click ");
Bt. sethorizontaltextposition (jbutton. center );
Bt. setverticaltextposition (jbutton. Bottom );
LB. sethorizontaltextposition (jlabel. center );
LB. setverticaltextposition (jlabel. Bottom );
CP. Add (LB, borderlayout. North );
CP. Add (BT, borderlayout. South );
Bt. seticon (PA );
Bt. setrololovericon (PB );
Bt. setpressedicon (PC );
Bt. addactionlistener (this );
}

Public void actionreceivmed (actionevent e )...{
If (E. getsource () = BT)
... {If (Lb. gettext () = "hello ")
LB. settext ("hello ");
Else
LB. settext ("hello ");
If (Bt. gettext () = "click ")
Bt. settext ("click ");
Else
Bt. settext ("click ");}

}

}

About imageicon (string filename)... it seems that you want to specify the absolute path .. Because I didn't specify the absolute path at first, even if I put the image file and. class in the same folder, it cannot be displayed normally ..

Supported images include GIF. jpg. JPEG and PNG versions starting from 1.3. ICO is not supported.

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.