Add a actionlistener to JTextArea and print out string when  the user input

Hello:
I got a problem to add a actionlistener to JTextArea and print out string which from the user input a sentence and after the user press the "enter".
Could anyone help me please?
Thanks
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.JScrollBar;
public class PanelDemo extends JFrame {
   private static JTextArea tAreaUp, tAreaDown;
   private BorderLayout layout;
   private static String strings;
   public PanelDemo()
      super( " test " );
      Container container = getContentPane();
      layout = new BorderLayout();
      container.setLayout( layout );
      tAreaUp = new JTextArea(2,1);
      tAreaUp.setLineWrap(true);
      tAreaUp.setWrapStyleWord(true);
      tAreaUp.setEditable(false);
      tAreaUp.append("I am testing ");
      tAreaUp.append("I am testing");
       JScrollPane scrollPane = new JScrollPane(tAreaUp);
       scrollPane.setVerticalScrollBarPolicy(
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
       scrollPane.setPreferredSize(new Dimension(250, 250));
      tAreaDown =new JTextArea(2,1);
      tAreaDown.setLineWrap(true);
      tAreaDown.setWrapStyleWord(true);
      tAreaDown.addActionListener(new TextAreaHandler());
      JScrollPane scrollPane2 = new JScrollPane(tAreaDown);
      scrollPane2.setVerticalScrollBarPolicy(
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      container.add( scrollPane, layout.CENTER );
      container.add( scrollPane2, layout.SOUTH );
      setSize( 300, 300 );
      setVisible( true );
     //private inner class for event handling
     private class TextAreaHandler implements ActionListener{
          //process textArea events
        public void actionPerformed(ActionEvent e){
           strings=e.getActionCommand();
            System.out.println(strings);
   public static void main( String args[] )
      PanelDemo application = new PanelDemo();
      application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}

Thanks for your help, but I still got a question for you.
Do you think the way I register the even handler to the TextArea is correct?
Because the compailer complains about that which like
"D:\101\fig13_27\PanelDemo.java:43: cannot resolve symbol
symbol  : method addActionListener (PanelDemo.TextAreaHandler)
location: class javax.swing.JTextArea
      tAreaDown.addActionListener(new TextAreaHandler());

Similar Messages

  • How do I get a PDF document put into an attachment form that I can drag to an e-mail.  Usually I get an icon showing an spiral note book which then becomes an attachment when I drag it to the e-mail, but occasionally it stays in PDF and prints out on the

    How do I get a PDF document put into an attachment form that I can drag to an e-mail.  Usually I get an icon showing an spiral note book which then becomes an attachment when I drag it to the e-mail, but occasionally it stays in PDF and prints out on the e-mail.  What have I done differently?

    Thanks again for the detailed instructions Srini!
    And I really hate to be a pest . . . but . . .
    Using your example and not modifying it, I get the e-mail form filled out correctly and the pdf attached, however, I'm not prompted to sign it.
    Any more clues?

  • A program that reads in secounds, and prints out hours minutes

    Hi, im new to Java and just testing something out. (Sorry for my bad english)
    How do i make a java application where the user input secounds, and the program "transforms" these secounds into hours, minutes and secounds.
    Like this:
    11873
    --> 3 hours, 17 minutes, 53 secounds.
    Anyone got a suggestion with some simple code?(so i can understand it )
    I cant find a way to do it.

    CYKO wrote:
    You're such a dickhead, you know that?
    Rookies don't get very good met here, im off.
    Really hope you sort ou your irl-issues, theres obviously some.Interesting, I've been called that by people that have had a far better idea of what they were talking about than yourself--you see I come from a school of education where the professor told us: After you've thought about it for days, banged your head against the wall and not had any valid results after hours of work, then come to me and I'll give you enough to get started. 54% of the class washed out before the very first test. (Oh, by the way, his great revelation on how to get started was: keep a pencil and paper by you at all times--you may wake up and know the answer: write it down then and there because you will not remember later.)
    I stood in the freshman class at the university I attended for undergrad work as president of our professional organization on campus and told them: "Look to your left. Now look to your right. On an average, if you make it through your chosen field of studies, everyone else in your row will not." It was a sobering fact for them, but they found out later just how true my words were. There were 12 rows--the university graduated 12 of them. That figure held true for my class too.
    So when a student comes in and trys to lay the guilt out on us... just know that we've been through it--where you are--and we are the ones that survived and excelled.
    Man-up and do what needs to be done to compete in school, it doesn't get any easier in the workplace. I'll not go through the details of trudging to class in the snow, not sleeping for 3 days straight to get assignments done, weeks at a time where I could count the number of hours of sleep on my fingers and not repeat any, working 35 hours a week and carrying a full college load, hit the books when all my friends were out partying... just to name a few things. So excuse me (us) if we turn a bit of a blind eye to your "emergency" we had them, we handled them, we made it because we paid the price. If you're not... well, you're not: just don't expect a sympathetic eye from those that took the pounding day after day and made it.

  • Error message "Enter a Printer" when the user clicks on PO out put preview

    Dear SRM Gurus,
    We are using SRM 5.5 extended classic scenario. When the user presses on Output Preview of PO we are getting a message that "Enter a Printer" and not able to see the preview. This messge we are getting for some particular PO's and for other we are able to see the preview.
    Please do the needful..
    Thanks and Regards,
    Chandra Sekhar.

    Hi
    <u>Please maintain default  Printer for Organizational user in PPOMA_BBP (Attribute  - PRI)...</u>
    <u><b>In PPOMA_BBP, your purch org must be defined under (or at the same level as) a company. This company org id (defined in function tab) will be used to read address and use it as "contact" addresse. Check this point, correct if necessary and tell me if this is ok.</b></u>
    <u>Also go through the useful related links -></u>
    Re: PO output
    Re: Add a Printer ?  -> LP01
    Re: Adding Send Medium to Vendor Record
    Re: Offline approval of SC
    <u>Do let me know.</u>
    Regards
    - Atul

  • How do I get System.out.format to print out doubles with the same precision

    Using the System.out.format, how do I print out the value of a double such that it looks exactly like it does if it were print from a System.out.println.
    For example, take the following code:
    double d = 12.48564734342343;       
    System.out.format("d as format: %f\n", d);
    System.out.println("d as   sout: " + d);Running the code, I get:
    <font face="courier">
    d as format: 12.485647
    d as sout: 12.48564734342343
    </font>
    The precision of d has been lost.
    I could bump up the precision as follows:
    double d = 12.48564734342343;
    System.out.format("d as format: %.14f\n", d);
    System.out.println("d as   sout: " + d);That appears to work, I get:
    <font face="courier">
    d as format: 12.48564734342343
    d as sout: 12.48564734342343
    </font>
    However, that solution fails if d has a different precision, say 12.48. In that case I get:
    <font face="courier">
    d as format: 12.48000000000000
    d as sout: 12.48
    </font>
    So how do I get System.out.format to print out doubles with the same precision as System.out.println?
    Thanks..

    YoungWinston wrote:
    Schmoe wrote:
    Interesting, but this is not what I am looking for...Your original question was "how do I print out the value of a double such that it looks exactly like it does if it were print from a System.out.println", and you've been told how to do that (although the pattern given by sabre may be a bit excessive - you should only need 15 '#'s).The initial phrase from my question was "Using the System.out.format, how do I..".
    It's worth remembering that, unlike the Format hierarchy, 'format()' is NOT native to Java. It's a convenience implementation of the 'printf()' and 'sprintf()' methods provided in C, and first appeared in Java 1.5. Those methods were designed to produced fixed-format output; 'println()' was not.Perhaps it is the case that this can't be done.
    Furthermore, Double.toString(), which is what is used by println() does not produce the same format in all cases; format("%.14f\n", d) does. TrySystem.out.println(1.8236473845783d);
    System.out.println(1823647384.5783d);and you'll see what I mean.I am fine with that. It still displays all the precision.
    I am simply looking for a way to quickly print out multiple variables on a sysout while debugging. I want it as syntactically sweet as possible. System.out.println can be a pain when outputting multiple variables like the following:
    "System.out.println("a: " + a + "; b:" + b + "; c: " + c);"
    For some reason, my fingers always typo the plus key.
    I was hoping that System.out.format would be easier,along the lines of:
    "System.out.format("a: %f, b: %f, c: %f\n", a, b, c);"
    From a syntactical sweetness point of view, it is easier. However, the %f on doubles truncates the precision. I figured there must be a way to get the full precision.
    DecimalFormat is syntactically sour for this purpose, as you need to instantiate the DecimalFormat.
    fwiw I have enjoyed reading the suggestions in this thread...

  • How to add a field to the selection screen and when the user enters ...

    hi all,
    can any one plesase send the code of how to add a field to seletiion screen and when the user enters in the field , it should be store in the database table , the table is MKPF and the field is BKTXT.  Thanks.

    Hi Kripa,
       If u r using PNP ldb then the screen u will get is the screen for that ldb and if u want to add some more fields then u define using selection-screen..as follows
    SELECTION-SCREEN BEGIN OF BLOCK mysel WITH FRAME TITLE text-111.
    PARAMETERS: n_in_en  RADIOBUTTON GROUP g1,
                q_ev  RADIOBUTTON GROUP g1.
    SELECTION-SCREEN END OF BLOCK mysel.
    SELECTION-SCREEN BEGIN OF BLOCK mysel1 WITH FRAME TITLE text-222.
    PARAMETERS: r_date TYPE sy-datum DEFAULT sy-datum.
    SELECTION-SCREEN END OF BLOCK mysel1.
    SELECTION-SCREEN BEGIN OF BLOCK mysel2 WITH FRAME TITLE text-333.
    PARAMETERS:f_ver(3) TYPE c DEFAULT 1,
               c_no(10) TYPE c DEFAULT '9D0161',
               u_id(15) TYPE c,
               password(15) TYPE c,
               r_email(30) TYPE c DEFAULT PARAMETERS: s_not TYPE c AS CHECKBOX.
    PARAMETERS:t_run TYPE c  AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK mysel2.
    SELECTION-SCREEN BEGIN OF BLOCK mysel3 WITH FRAME TITLE text-444.
    SELECTION-SCREEN BEGIN OF BLOCK mysel4 WITH FRAME TITLE text-555.
    PARAMETERS: p_ser  RADIOBUTTON GROUP g2,
    a_ser  RADIOBUTTON GROUP g2.
    SELECTION-SCREEN END OF BLOCK mysel4.
    SELECTION-SCREEN BEGIN OF BLOCK mysel5 WITH FRAME TITLE text-666.
    PARAMETERS:p_path TYPE string.
    SELECTION-SCREEN END OF BLOCK mysel5.
    SELECTION-SCREEN END OF BLOCK mysel3.
    u will get this additional screen after the screen of ldb.
    I hope this will help u..
    Thanks & Regards
    Ashu Singh.

  • How to fade in and fade out audio in the new version of Imovie?

    Please help me!
    how to fade in and fade out audio in the new version of Imovie?

    There is a tiny dot at the beginning and ending of an audio clip that can be moved to adjust fade in and fade out.

  • Why can't GB let me use 'electric guitar' option when using Nio 2/4 interface - I have to use real instrument and miss out on all the effects. Is this normal for all interfaces?

    Why can't GB let me use 'electric guitar' option when using Nio 2/4 interface - I have to use real instrument and miss out on all the effects. Is this normal for all interfaces? The Nio reads hte guitar but GB doesn't....

    Usually effects packages are AU plugins that would have no effect on track selection. Interfaces should have no control over what kind of track you can select. I really think something else is going on her maybe something you overlooked.
    Did you choose the input channel in the track info pane. Try both channel 1 mono or channel 2 mono. Make sure the track is record enabled.

  • HT5446 if i order a new imac with 1tb flash is that pcie based to where i could add a 3.5 ssd and does it still have the bracket and sata cable to add one in it

    if i order a new imac with 1tb flash is that pcie based to where i could add a 3.5 ssd and does it still have the bracket and sata cable to add one in it

    Be advices that the newest iMac's are basically SEALED Units and taking it apart in any way, other than removing the Memory slot cover to add more RAM (That is on the 27" model. The 21.5" is completely sealed), will void the warranty on it.
    Not only that but the screen is Glued to the aluminum casing and if you do pry it off with damaging it you'll need new adhesive strips to remount it.
    Not worth the efford or the cost when you can buy mat any other brand computer for less money and do all the upgrading you would ever want without ever voiding the warranty or breaking something in the process.

  • Will this SB1 reporting and printing forum will override the B1 forum ?

    Hi All,
    Will this SB1 reporting and printing forum will override the B1 forum ? If not, it means that the B1 will be purely the application or functional such as query FMS, store procedure or any work around.
    Rgds,

    Hello Jimmy,
    There is today a demand for a forum relating to printing and reporting for SAP Business One. We have taken the strategy to go for functional forums like this. This forum will in no way replace the main Business One forum, it is intended to compliment it. As we move further into the forums and as we reach ceilings in forums we will break them down into further functional forums such as this. There is a lot of threads relating to printing and reporting and Crystal Reports so we created this thread. I know you are a large contributor and hope that you can share your knowledge to these new forums.
    Regards,
    Paul Finneran
    SAP Business One Forums Team

  • How do I sign my VB / VS 2010 based shared COM add-in for Excel so it loads when the user has checked "Require application add-ins to be signed by a trusted publisher"?

    My COM add-in is developed using VS 2010 and VB. It's a shared COM add-in (not VSTO) and it works with Excel 2007 - 2013. My installer is signed with a code signing certificate but it would appear that my add-in's .dll should also be signed if the user has
    checked the "Require application add-ins to be signed by a trusted publisher" option.
    The "Sign the assembly" option is checked in my add-in's VB -> My Project -> Signing. I have a .snk file selected which I seem to recall generating 6 or 7 years ago when I ported the COM add-in from VB6 to .NET. 
    I have an up-to-date Comodo code signing certificate (a pfx file called MyCompanyCodeSigningCertificatePrivateKey.pfx) which I purchased to use with the installer and was wondering if and how I could use this.
    I tried selecting my pfx file in the My Project -> Signing -> "Choose a strong name key file" dialog. It made a copy of the pfx file in my project folder but when I tried to build the project, I got the following error:
    Error 1 Cannot import the following key file: MyCompanyCodeSigningCertificatePrivateKey.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the
    following key container name: VS_KEY_C0B6F251F0FB6016
    After a little research, I found out I might be able to use signtool to sign the dll in a post-build step.
    I added the following command to the post-build event, before the command I use to regasm the assembly.
    "path to signtool\signtool" sign /f "MyCompanyCodeSigningCertificatePrivateKey.pfx" /p "xxxx" /v "$(TargetPath)"
    When I built the project, the dll appeared to get signed (the output window showed a bunch of confirming text as well as "Successfully signed: c:\MyAddIn\bin\Release\MyAddIn.dll") but the next step in the post-build (regasm myaddin.dll /codebase)
    issued a warning RA0000 (see below) but reported "Types registered successfully".
    Here's the message I get from regasm, even though the output window says the dll was sucessfully signed:
    RegAsm : warning RA0000: Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
    Types registered successfully
    I'm not using a shim if that makes a difference.
    How do I sign my add-in so it loads when the user has checked "Require application add-ins to be signed by a trusted publisher"?
    Any tips would be appreciated.

    Hello,
    Why do you need to use the regasm utility from the post-build action?
    There is a difference between signing the assembly with a strong name and digital signature. The
    How to: Sign an Assembly with a Strong Name article in MSDN explains how to sign an assembly with a strong name (.snk). See
    How to digitally sign a strong named assembly for adding a digital signature.
    You may also find the
    What's the Difference, Part Five: certificate signing vs strong naming article helpful.

  • What are the ports required for the Audio, Video and A/V conferencing when the following end points are enabled for QoS in Lync 2013 server?

    Hi All,
    What are the ports required for the Audio, Video and A/V conferencing when the following clients are enabled for QoS in Lync 2013 server?
    Client Type
    Port range  and Protocol required for Audio
    Port range and Protocol required for
    Video
    Port range and Protocol required for
    A/Vconferencing
    Windows Desktop   Client
    Windows mobile App
    Iphone
    Ipad
    Andriod phone
    Andriod Tablet
    MAC desktop client
    Please advise. Many Thanks.

    Out of the box, 1024-65535 for all of the client ports.  :) 
    https://technet.microsoft.com/en-us/library/gg398833.aspx
    You'll want to tune your client ports a bit
    https://technet.microsoft.com/en-us/library/jj204760.aspx as seen here, and then the client ports would use those ranges which is easier to set QoS markings.  I'm not sure the mobile clients respect that setting.
    Elan's got the best writeup for Windows clients here:
    http://www.shudnow.net/2013/02/16/enabling-qos-for-lync-server-2013-and-various-clients-part-1/
    However, the marking of the packets is the tricky part.  Windows can do it via Group Policy, but for the other clients you'll need to have the network specifically prioritize ports regardless of DSCP markings.  You have to do it based on ports
    as the traffic could be peer to peer.
    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question please click "Mark As Answer".
    SWC Unified Communications
    This forum post is based upon my personal experience and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • Print parameters as per the user selection in ALV

    Hi All,
    We have a requriment for getting the print parametrs to print dialog as per the user selection in ALV list display.
    When the user click on 'Print' button In ALV list output screen, we need to capture the print parameters from a Z table and put those on the print parameters dialog box.
    I tried this , by calling the function GET_PRINT_PARAMETERS and SET_PRINT_PARAMETERS before the alv function is called. Unforutnately this is not working. Same code works for the simple list display.
    Have anyone worked with this kind of requriment ?
    Regards,
    Mithun

    What kind of ALV are you using, FM or OO?
    Regards,
    Rich Heilman

  • My macbook pro shuts down OSX and all my programs when the lid is closed

    Hi,
    I am having a problem. My macbook pro shuts down OSX and all my programs when the lid is closed. I close the lid, and then I hear the shutdown music and then when I open it again it automatically restarts OSX and all my windows and programs are closed, any info gone.
    This doesn't happen all the time. Just once a day or maybe twice a day. It seems like it happens basically when I have my computer just the way I want it, to keep an eye on things for the day.
    I just recently switched to a mac and while somewhat savvy, I am not a programmer or techie, but it seems to me that when I shut the lid, it should do the same thing every time.
    I have a intel core 2 duo 17 inch macbook pro with 2.33 processr and 2 gig ram, if that helps.
    I am in alaska and there is no genius bar here and I am hoping to figure this out before I begin bugging our local independant mac store about this.
    Thanks in advance,
    Lylah
    17 inch Macbook Pro   Mac OS X (10.4.9)   intel core 2 duo 2.33g. 2 gig ram

    Ahhh, enlightenment!
    That would make sense. What I usually do, after closing the lid, is to wait for the apple to turn off and then set it down on it's side leaning it against the side table. I will try to wait for it to indicate that it is fully asleep before I move it next time. Personally, I prefer my computer to NOT fall asleep at all, but I am told it is not an option. Apparently this function is hardware related accoring to my local mac shop. They tracked it down for me because I hated this feature when I first bought my computer and was trying some way around it.
    The shutdown music I was refering to was that music the mac makes when shutting down, which doesnt usually occur when it goes to sleep, unless it is malfunctioning like this.
    What does resetting the pmu do? (what is a pmu as well?)
    Thank you very much.
    Lylah

  • TS1410 My iPod shuffle ( 1st or 2nd generation) will not recharge and does not show when the doc is connected to my MacBook Pro. I'm running the latest updated version of iTunes.

    My iPod shuffle ( 1st or 2nd generation) will not recharge and does not show when the doc is connected to my MacBook Pro. I'm running the latest updated version of iTunes.

    Hello Jane Benstock,
    Thank you for using Apple Support Communities
    It sounds like the next best step to take would be to reset the iPod Shuffle.
    Check out this article named Resetting iPod shuffle found here http://support.apple.com/kb/HT1655.
    All the best,
    Sterling

Maybe you are looking for