Java image interface development simple example-Application of jcheckbox and jlabel

Source: Internet
Author: User

Java image interface development example

The jlabel component is used to display text information. The jcheckbox component is used to set text attributes. The Code is as follows:

Import java. AWT. borderlayout;
Import java. AWT. Font;
Import java. AWT. event. actionevent;
Import java. AWT. event. actionlistener;

Import javax. Swing. jcheckbox;
Import javax. Swing. jframe;
Import javax. Swing. jlabel;
Import javax. Swing. jpanel;

/**
* Application Instances of jcheckbox and jlabel
* @ Author Zuo Jie jdk5.0
*/
Public class example9frame extends jframe {

/**
*
*/
Private Static final long serialversionuid = 1l;
Private jlabel label;
Private jcheckbox bold;
Private jcheckbox italic;
Private Static final int fontsize = 14;
Public example9frame (){
Settitle ("jcheckbox application"); // set the Form title
Setsize (500,300); // set the form size
// Create a jlabel component to display text information
Label = new jlabel ("this is a simple application instance of the jcheckbox component. This is the test text! ");
Label. setfont (new font ("", Font. Plain, fontsize); // set the text font size
Add (Label, borderlayout. center); // Add the jlabel component to the form.
// Create an event listening object
Actionlistener listener = new actionlistener (){
Public void actionreceivmed (actionevent event ){
Int mode = 0;
If (bold. isselected () // whether to bold
Mode + = font. Bold;
If (italic. isselected () // whether it is Italic
Mode + = font. italic;
Label. setfont (new font ("", mode, fontsize); // reset the text
}
};
// Create a panel add check box
Jpanel Panel = new jpanel ();
// Create the jcheckbox component
Bold = new jcheckbox ("bold ");
Italic = new jcheckbox ("italic ");
// Add a listener for the jcheckbox component
Bold. addactionlistener (listener );
Italic. addactionlistener (listener );
// Add the jcheckbox component to the Panel
Panel. Add (BOLD );
Panel. Add (italic );
// Add the panel to the form
Add (panel, borderlayout. South );
}

Public static void main (string [] ARGs ){
Example9frame frame = new example9frame ();
Frame. setdefaclocloseoperation (jframe. exit_on_close );
Frame. setvisible (true );
}
}

Related Article

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.