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

Source: Internet
Author: User

Java image interface development example

For jradiobutton, jcheckbox, and jlabel applications, you only need to modify the jcheckbox and jlabel applications and add single-choice buttons. A set of note single-choice buttons must be placed in the buttongroup to take effect. 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. buttongroup;
Import javax. Swing. jcheckbox;
Import javax. Swing. jframe;
Import javax. Swing. jlabel;
Import javax. Swing. jpanel;
Import javax. Swing. jradiobutton;

/**
* Jradiobutton, jcheckbox, and jlabel Application Instances
*
* @ Author Zuo Jie jdk5.0
*/
Public class example10frame extends jframe {

/**
*
*/
Private Static final long serialversionuid = 1l;

Private jlabel label;

Private jcheckbox bold;

Private jcheckbox italic;

Private buttongroup group;

Private jpanel;

Private Static int fontsize = 14; // global font size

Private Static int modes = 0; // global font Model

Public example10frame (){
Settitle ("jradiobutton 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 test text! ");
Label. setfont (new font ("", modes, 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
Modes = mode;
}
};
// Create a check box and a single button for adding a panel
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 );
// Create a buttongroup object. The single-choice button must be added to this group for practical purpose.
Group = new buttongroup ();
// Add a radio button
Addradiobutton ("small", 8 );
Addradiobutton ("default", fontsize );
Addradiobutton ("big", 20 );
// Add the panel to the form
Add (panel, borderlayout. South );
}

Public void addradiobutton (string name, final int size ){
Boolean selected = size = fontsize; // select whether the font is the same as the default font.
Jradiobutton button = new jradiobutton (name, selected); // create jradiobutton button
Group. Add (button); // Add the jradiobutton button to the button group
Panel. Add (button); // Add the button to the Panel
// Create a jradiobutton event listener
Actionlistener listener = new actionlistener (){
Public void actionreceivmed (actionevent event ){
// Set the font
Label. setfont (new font ("", modes, size ));
Fontsize = size;
}
};
// Add a listener for the jradiobutton button
Button. addactionlistener (listener );
}

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

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.