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 );
}
}