Chapter 6 Exercise 6 of Java programming ideology

Source: Internet
Author: User

The question is simple. Get the strings in jtextarea and jtextfield, perform the operation, and put the result in another jtextarea.

 

Import javax. Swing .*;
Import java. AWT .*;
Import java. AWT. event .*;
Import static util. swingconsole .*;
Import java. util. RegEx .*;

Public class textarea extends jframe
{
Private jbutton B = new jbutton ("click ");
Private jtextarea T1 = new jtextarea (5, 10 );
Private jtextarea t2 = new jtextarea (5, 10 );
Private jtextfield TF = new jtextfield (10 );
Public textarea ()
{
B. addactionlistener (New actionlistener (){
Public void actionreceivmed (actionevent e ){
String name = t1.gettext ();
String Match = TF. gettext ();
Pattern P = pattern. Compile (MATCH );
Matcher M = P. matcher (name );
T2.settext (""); // used to clear Initialization
While (M. Find ())
{
T2.append ("Match \" "+ M. group () + "\" at positions "+ M. start () + "-" + (M. end ()-1) + "\ n ");
}
}});
Setlayout (New flowlayout ());
Add (New jscrollpane (T1 ));
Add (B );
Add (New jscrollpane (T2 ));
// Add (B );
Add (TF );
}
Public static void main (string [] ARGs)
{
Run (New textarea (), 475,425 );
}
}

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.