Java image interface development example-jtextarea, jscrollpane, jpanel, jbutton application example

Source: Internet
Author: User

Java image interface development example

The jtextarea, jscrollpane, jpanel, and jbutton Application Instances use the 'insert text' Button Function to write test text. The line feed function can be used for line breaks and line breaks. The Code is as follows:

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

Import javax. Swing. jbutton;
Import javax. Swing. jframe;
Import javax. Swing. jpanel;
Import javax. Swing. jscrollpane;
Import javax. Swing. jtextarea;

/**
* Jtextarea, jscrollpane, jpanel, and jbutton Application Instances
* @ Author Zuo Jie JDK 5.0
*/
Public class example8frame extends jframe {

Private Static final long serialversionuid = 1l;
Private jtextarea textarea; // text field
Private jscrollpane scrollpane; // With a scroll bar panel
Private jpanel buttonpanel; // store the button panel
Private jbutton wrapbutton; // line feed button
Public example8frame (){
Settitle ("text editing"); // sets the Form title
Setsize (300,300); // set the form size
// Create the jtextarea component
Textarea = new jtextarea ();
// Create the jscrollpane panel and place the jtextarea component into the panel with a scroll bar
Scrollpane = new jscrollpane (textarea );
/// Add a scroll bar panel to the form
Add (scrollpane, borderlayout. center );

Buttonpanel = new jpanel (); // create a button panel
// Create the insert text button, add the click event, and add the test text
Jbutton insertbutton = new jbutton ("insert text"); // create the "insert text" button
Buttonpanel. Add (insertbutton); // Add this button to the Panel
// Add event listening for this button
Insertbutton. addactionlistener (New actionlistener (){
Public void actionreceivmed (actionevent event ){
Textarea. append ("this is a simple application instance of the textarea component. This is the test text! "); // Add text information to the jtextarea component
}
});
// Add the "line feed" button and add click events to control line breaks and non-line breaks
Wrapbutton = new jbutton ("newline"); // create the "newline text" button
Buttonpanel. Add (wrapbutton); // Add this button to the Panel
// Add event listening for this button
Wrapbutton. addactionlistener (New actionlistener (){
Public void actionreceivmed (actionevent event ){
Boolean wrap =! Textarea. getlinewrap (); // gets the line feed status of the jtextarea component. The default value is false.
Textarea. setlinewrap (WRAP); // reset whether to set the line feed attribute.
Wrapbutton. settext (wrap? "Do not wrap": "Wrap"); // display text based on the Property setting button
}
});
// Add a button panel to the form
Add (buttonpanel, borderlayout. South );
}
Public static void main (string [] ARGs ){
Example8frame frame = new example8frame ();
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.