Trying to get a button to update Jtextarea on a frame..

Hi,
This a newbie. I have the following code but can't figure out how to append data I read into a string into JTextArea...
The code builds the frame which implements action listener.
               outputArea = new JTextArea("Books", 15, 15);
               container.add(outputArea);
I'm trying to append a string to the outputArea but the code does not fire...
The code is in a seperate event class
if ( event.getSource() == showButton )
f or ( int i = 0; i <= book.length; i++)
                         bookString += book.toBookString();
                         outputArea.append(bookString);
Could it be the scope of the outputArea variable? I have tried to add other things to the frame in the ActionListener class but nothing seems to work. The actions work on other buttons. I just can't seem to append the JTextArea on my frame.
Any thoughts out there?

Any thoughts out there?Where you create your GUI
(1) Check that the button and output area are the same ones that are later
referred to in the event handler. You often see the (wrong)class MyFrame {
    private JButton button;
    MyFrame() {
        JButton button = new JButton();
}(2) Check that the event listener has been added as a listener.
(3) Put a System.out.println(); at the start of the event listener to check that
it really is not being fired. (As distinct from your bookString ending up empty
for instance).
If all else fails constructing a small example that compiles and illustrates
your problem. If you do this, use the code tags described here:
http://forum.java.sun.com/help.jspa?sec=formatting
Basically the idea is that you start your code with [code] and end it with [/code].
That way if you post something like
[code]if(tagsUsed) {
System.out.println("Output looks nice");
}[/code]
It will appear like if(tagsUsed) {
    System.out.println("Output looks nice");
}(In general you should post Swing questions to the Swing forum.)

Similar Messages

  • How to I stop Firefoc continually trying to get me download an update 8.1 that my computer didn't seem to like so I uninstalled

    I was invited to upgrade to Firefox 8.1 but my old computer decided it didn't like it & kept messing up so I uninstalled it. Now Firefox 8.1 is continually popping up for me to download & is frankly a blinking nuisance. How do I get it to stop doing this?

    See:
    * https://support.mozilla.com/en-US/kb/Updating%20Firefox#w_how-do-i-configure-update-options

  • I can't get my Button to work?

    Hello everyone,
    I been trying to get my Button working, but I don't understand what's wrong. I've tried a bunch of stuff, each with failure. Can any of you guys help me out here? I know that it's a little bit of a mess, but for some reason, it gives me a NullPointerException when I execute it. If I comment out 4 lines of code, about the getContentPane, it works without making a button. Problem is, I want to keep the Button in there. What should I do?
    Thanks
    import com.brackeen.javagamebook.graphics.ScreenManager;
    import com.brackeen.javagamebook.graphics.ScreenManager;
    import com.brackeen.javagamebook.sound.SoundManager;
    import com.brackeen.javagamebook.graphics.NullRepaintManager;
    import com.brackeen.javagamebook.input.*;
    import com.brackeen.javagamebook.input.GameAction;
    import com.brackeen.javagamebook.graphics.*;
    import com.brackeen.javagamebook.sound.*;
    import com.brackeen.javagamebook.test.GameCore;
    import java.util.List;
    import java.util.ArrayList;
    import javax.swing.border.Border;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.io.File;
    import java.awt.event.KeyListener;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.midi.Sequence;
    import java.applet.AudioClip;
    import javax.sound.midi.Sequencer;
    import java.awt.image.BufferStrategy;
    import java.awt.image.BufferedImage;
    import java.lang.reflect.InvocationTargetException;
    public class Graphic2 implements ActionListener
         public static void main(String[] args)
    new Graphic2().run();
    private JPanel startButtonSpace;
    private static final long DEMO_TIME = 30000;
    private static final String EXIT = "Exit";
    private ScreenManager screen;
    private ActionListener action;
    private Image Background, Title, Start;
    private boolean isRunning;
    private Sequence music;
    private SoundManager soundManager = new SoundManager(PLAYBACK_FORMAT);
    private MidiPlayer midiPlayer;
    private Sound titleMusic;
    //Uncompressed, 44100Hz, 16-bit, Sterio, Signed, Little-Endian
    private static final AudioFormat PLAYBACK_FORMAT =
    new AudioFormat(44100, 16, 2, true, false);
    protected InputManager inputManager;
    protected GameAction configAction;
    protected GameAction exit;
    private JButton startButton;
    private static final DisplayMode POSSIBLE_MODES[] = {
    new DisplayMode(1024, 768, 32, 0),
    new DisplayMode(1024, 768, 24, 0),
    new DisplayMode(1024, 768, 16, 0),
    new DisplayMode(800, 600, 32, 0),
    new DisplayMode(800, 600, 24, 0),
    new DisplayMode(800, 600, 16, 0)
    public void loadImages()
    // load images
    Background = loadImage("Title Screen.jpg");
    Title = loadImage("Title.gif");
    Start = loadImage("Start.gif");
    public Image loadImage(String fileName)
    return new ImageIcon(fileName).getImage();
    public void animationLoop()
    long startTime = System.currentTimeMillis();
    long currTime = startTime;
    while (isRunning)
    long elapsedTime = System.currentTimeMillis() - currTime;
    currTime += elapsedTime;
    // draw and update screen
    Graphics2D g = screen.getGraphics();
    draw(g);
    g.dispose();
    screen.update();
    // take a nap
    try
    Thread.sleep(20);
    catch (InterruptedException ex) { }
    public void initSounds()
    //midiPlayer = new MidiPlayer();
    titleMusic = soundManager.getSound("movie02.wav");
    //music = midiPlayer.getSequence("potc.mid");
    public void run()
         NullRepaintManager.install();
         isRunning = true;
         initSounds();
         NullRepaintManager.install();
         screen = new ScreenManager();
         JFrame frame = screen.getFullScreenWindow();
    // create buttons
    startButton = createButton("Start.gif");
    startButton.setLocation(460, 500);
    //frame.getContentPane().setLayout(new FlowLayout());
    //frame.getContentPane().add(startButton);
    try
    DisplayMode displayMode =
    screen.findFirstCompatibleMode(POSSIBLE_MODES);
    screen.setFullScreen(displayMode);
    loadImages();
    soundManager.play(titleMusic);
    //if (frame.getContentPane() instanceof JComponent)
         //((JComponent)frame.getContentPane()).setOpaque(false);
    animationLoop();
    finally
    screen.restoreScreen();
    soundManager.stop();
    frame.validate();
    Window window = screen.getFullScreenWindow();
         public void draw(Graphics2D g)
    // draw background
    g.drawImage(Background, 0, 0, null);
    // draw image
    g.drawImage(Title, 342, 244, null);
    //g.drawImage(Start, 460, 500, null);
    public void actionPerformed(ActionEvent e)
    Object src = e.getSource();
    if (src == startButton)
    exit.tap();
    public void checkSystemInput()
    if (exit.isPressed())
    stop();
    public void stop()
    isRunning = false;
    public void createGameActions()
    exit = new GameAction("exit",
    GameAction.DETECT_INITAL_PRESS_ONLY);
    inputManager.mapToKey(exit, KeyEvent.VK_ESCAPE);
    public JButton createButton(String name)
    // load the image
    String imagePath = name;
    ImageIcon iconRollover = new ImageIcon(imagePath);
    int w = iconRollover.getIconWidth();
    int h = iconRollover.getIconHeight();
    // get the cursor for this button
    Cursor cursor =
    Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
    // make translucent default image
    /*Image image = screen.createCompatibleImage(w, h);*/
    Graphics2D g = screen.getGraphics();
    /*g.drawImage(iconRollover.getImage(), 0, 0, null);*/
    // create the button
    JButton button = new JButton();
    button.addActionListener(this);
    button.setIgnoreRepaint(true);
    button.setFocusable(false);
    button.setBorder(null);
    button.setContentAreaFilled(false);
    button.setCursor(cursor);
    button.setIcon(iconRollover);
    button.setRolloverIcon(iconRollover);
    button.setPressedIcon(iconRollover);
    return button;
    }

    1) Swing related questions should be posted in the Swing forum
    2) Use the "code" formatting tags when posting code so the code is readable.
    3) Post [url http://www.physci.org/codes/sscce.jsp]Simple, Executable Sample that shows your problem. The code you posted uses non-standard API's so we can't execute your code to see the incorrect behaviour.
    4) Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/button.html]How to Use Buttons. Or maybe the section on "How to Use Layout Managers" will solve your problem. Either way read the tutorial.

  • My back button and refresh button and my yahoo tool bar are dimmed a lot when I open up firefox. So as a result, I cannot use the back button nor my refresh button AND my yahoo toolbar disappears a lot. I have tried to get on your chat session but it is a

    <blockquote>Locked by Moderator as a duplicate/re-post.
    Please continue the discussion in this thread: [/forum/1/688252]
    Thanks - c</blockquote>
    == Issue
    ==
    I have another kind of problem with Firefox
    == Description
    ==
    My back button and refresh button and my yahoo tool bar are dimmed a lot when I open up firefox. So as a result, I cannot use the back button nor my refresh button AND my yahoo toolbar disappears a lot. I have tried to get on your chat session but it is always closed. I need one on one help. Please reply with resolution.
    == This happened
    ==
    Every time Firefox opened
    == two or three months ago
    ==
    == Firefox version
    ==
    3.6.3
    == Operating system
    ==
    Windows XP
    == User Agent
    ==
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 (BT-canvas) Firefox/3.6.3 GTB7.0 (.NET CLR 3.5.30729)
    == Plugins installed
    ==
    *-npdnu
    *npdnupdater2
    *Coupons, Inc. Coupon Printer DLL
    *Coupons, Inc. Coupon Printer Plugin
    *The QuickTime Plugin allows you to view a wide variety of multimedia content in Web pages. For more information, visit the QuickTime Web site.
    *6.0.12.448
    *RealPlayer(tm) LiveConnect-Enabled Plug-In
    *RealJukebox Netscape Plugin
    *Default Plug-in
    *Adobe PDF Plug-In For Firefox and Netscape "9.3.2"
    *BrowserPlus -- Improve your browser! -- http://browserplus.yahoo.com/
    *Shockwave Flash 10.0 r45
    *Yahoo Application State Plugin version 1.0.0.7
    *3.0.50106.0
    *My Web Search Plugin Stub for 32-bit Windows
    *Google Updater pluginhttp://pack.google.com/
    *Google Update
    *Next Generation Java Plug-in 1.6.0_20 for Mozilla browsers
    *Npdsplay dll

    * If the menu bar is hidden then press and hold the Alt key down, that should make the Menu bar appear (Firefox 3.6 on Windows) (see [[Menu bar is missing]]).
    * Make sure that you have the ''Navigation Toolbar'' and other toolbars visible: View > Toolbars .
    * If items are missing then see if you can find them in the View > Toolbars > Customize window.
    * If you see the item in the Customize window then drag it back from the Customize window to the Navigation toolbar.
    * If you do not see that item then click the Restore Default Set button in the View > Toolbars > Customize window.
    See also [[Back and forward or other toolbar buttons are missing]] and [[Navigation Toolbar items]]
    See http://kb.mozillazine.org/Toolbar_customization

  • While i was updating my ipod touch it had an error and froze at the apple logo with a loading bar underneath.How do I fix it? Its stuck there,  tried everything, turn off button home screen button even the volume buttons, nothing is working.

    I was updating my ipod touch and the updation had an error and it froze at the apple logo with the loading bar underneath. How do I fix it? I tried the turn off button home screen button and even the volume buttons. I cant get anything to work. Please help me.

    Connect to itunes and retore.

  • Trying to get Ipod to Update songs from ITunes

    I have downloaded a whole stack of CDs into iTunes but I can't get my Ipod to Update with the new stuff.
    Ever since I got my iPod (40GB) I have had problems with this. Sometimes I just have to go round and round in circles til the computer takes pity on me and it works (or at least, that's how it feels!!) but this week, it's having none of it and it's driving me nuts.
    The manual says that if the option is set up, the IPod will automatically update when it is connected to the PC - but it doesn't (and the option is definitely set up right). My PC recognises that I have plugged it in and when I take it out, by making a noise, but the songs are not updating.
    Can anyone help at all? The Ipod is fully charged, I have updated all software, tried re-setting, it is switched on etc. I don't want to start again as I have over 4000 songs in on my iPod and I don't want to have to download them all again.
    Hoping someone out there can help. If not, watch your heads cos there's an Ipod about to be launched through a window!!! lol.

    Thanks, but it didn't help.
    However - I did finally get it to work!!!
    I just kept resetting the Ipod, plugging it into my PC and updating the software until it finally did the update properly and then it finally updated my IPod!!
    It has always been a problem, but this was longer than usual before it did it.
    All I can suggest to others out there with the same problem is to make sure that your Ipod is completely charged before you start trying to update your Ipod. Re-boot your PC and then try again when everything is "fresh" etc.
    Keep resetting the Ipod whilst it is plugged into the PC - press and hold the menu and select button for 6-10 seconds until the apple logo appears. When I did this, my PC kept making the noise like when you unplug it or plug it in and the PC recognises it - even though I hadn't unplugged it.
    Eventually I got a message saying the software needed updating and to click on the "update" option (as far as I was aware, I had done this 4 times already, but I did it again anyway!). Part way through I got an icon on my Ipod saying to plug it into the mains to charge it (showing a plug going into plug socket). I did that, plugged it back into pc when it was fully charged again and Itunes finally recognised it and updated the Ipod.
    A lot of messing and freaking annoying, but I got there in the end. Good luck to everyone else!!!

  • TS1702 I'm trying to get free app, but it just show me FREE button without download in iPhone 5

    I'm trying to get free app, but it just show me FREE button without download in iPhone 5.
    On MacBook PRO in iTunes I have the error:
    "Could not purchase "xxxxxx". An unknown error occurred (5002).
    There was an error in the iTunes Store. Please try again later."
    But I can purchase on iPad throught the same Apple ID

    Hi The Magic Tech,
    Thanks for visiting Apple Support Communities.
    You may find the steps in this article helpful:
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    If you haven't been able to connect to the iTunes Store, a software conflict or your internet service provider (ISP) may be blocking your access.
    Update iTunes to the latest version.
    If you have a firewall, your settings may be preventing you from connecting to the iTunes Store. To configure your firewall, please refer to the "Blocked by firewall" section in this article.
    You may need to reset your keychain. Connection issues are occasionally caused by keychain issues. Click here to find out how to use Keychain First Aid to resolve any issues with your keychain.
    If you are receiving a specific error message you may want to see, the "Specific Conditions and Alert Messages" section in this article as needed.
    If the issue still persists, contact your internet service provider and confirm that the ports and servers in this articleare enabled over your network.
    All the best,
    Jeremy

  • I downloaded the latest iOS7 to my iPad and then the screen went blank and would not respond.   I have tried pressing the two buttons together and briefly get the Apple logo but still can not start up, the logo disappears.   I have tried connecting the iP

    I downloaded the latest iOS7 to my iPad and then the screen went blank and would not respond.   I have tried pressing the two buttons together and briefly get the Apple logo but still can not restart, the logo disappears.   I have tried connecting to my iMac to restore the iPad but the device does not show up (I have an old iMac).   What else can I do?

    You need to be running Snow Leopard 10.6.8 at the very least in order to sync your iPad with iTunes so you could update your Mac, if it can be updated, and if you care to do so.
    If that's not an option, you will have to find someone that can restore the device for you with their computer running iTunes or make an appointment at an Apple Store and ask them to restore the device for you.
    I hope that you have an iCloud backup, because you will lose everything on the device when it is restored.
    Snow Leopard can still be purchased in the U.S. Apple Online Store.
    http://store.apple.com/us/product/MC573Z/A/mac-os-x-106-snow-leopard
    Also, I would not give up on the reset technique....holding down on the sleep and home buttons at the same time until the Apple logo appears. It takes about 10-15 seconds and sometimes just a little longer to get the logo to appear.

  • HT201412 I have to hit my home button a half dozen times to make it work.  I've tried to reset the phone and updated the software.  Is this a hardward problem?

    I have to hit my home button a half dozen times to make it work.  I've tried to reset the phone and update the sorfware.  Is this a hardware problem?  Where do I go to get it fixed?

    At Apple Store this is handled with Replacement iPhone exactly like yours. If there is AppleCare or Warranty it will be covered, otherwise there will be a charge of $150 - $199 depending on iPhone model. If iPhone 5 it will be covered. If you want to try Virtual Home Button. Settings App > General > Accessibility > Assistive Touch > ON > tap new white screen button > Home.

  • I just tried to install the 11.4 update (or whichever one is the most recent update as of 1/26/2014) and when it failed i tried to install manually and now whenever i try to use it, i get the following error: the application has failed to start because MS

    i just tried to install the 11.4 update (or whichever one is the most recent update as of 1/26/2014) and when it failed i tried to install manually and now whenever i try to use it, i get the following error: "The application has failed to start because MSVCR80.dll was not found. Re-installing the application may fix this problem." Right after i click ok i then get this error: "Itunes was not installed correctly. Please reinstall Itunes. Error 7 (Windows error 126)." I tried to uninstall Itunes and then reinstall the 11.03 version but that didnt work either. I want to know if i copy all of the music in my itunes folder to an external without consolidating can i still transfer all my itunes music from my current windows xp pc to a brand new one and have my current itunes library in my new pc? Basically i just want to know 3 things: What exactly does consolidating the itunes library do? Can i copy, paste, and transfer my itunes library to an external and from there to a new pc? Will i be able to transfer my itunes library without consolidating the files?

    I have found a temporary solution, allowing the previous version of iTunes (v. 11.1.3 (x64) in my case) to be re-installed.  It will allow you to re-establish use of iTunes until the Apple software engineers fix the most recent disasterous upgrade (v. 11.1.4).  Please see and follow the procedure in the following article:http://smallbusiness.chron.com/reverting-previous-version-itunes-32590.html   The previous version works beautifully.

  • Latest update of Muse is not installing on several tries,installation gets stuck at 43% and shows '' waiting'' at the  ''Extracting''  stage for 7-8 hours after which it does not progress

    latest update of Muse is not installing on several tries,installation gets stuck at 43% and shows '' waiting'' at the  ''Extracting''  stage for 7-8 hours after which it does not progress.

    Refer to EX11....
    Creative Cloud Error Codes (WIP) | Mylenium's Error Code Database
    Mylenium

  • I am trying to get ios 4.3 softeware update for iPad1. When I plug in my iPad to my PC, mu PC tinks that it is a digital Still Camera and will not go any further.

    I am trying to get ios 4.3 software update for my iPad 1. Have downlosded Itunes and apple softwareupdates to my PC, but when I plug in my iPad the computer thinks it is a digital still camera.  how do I get my PC to reconize that it is an iPad

    Must point out that this is the first time I have ever tryed to update my iPad, other than when I got it started at the store where I abought it. 
    This is what is happening to me.  the PC is on and I have3 the Itunes on the screen but as soon as I plug in my iPad my PC seems to think that it is a digital still camera and emediatly starts suting down as it seems to think the iPad(digital camera) is going to harm my PC.  PC will not go anyfurther than a warning screen and I have to then shut it down  unplug the iPad and start again.  HELP please

  • I am trying to create a button in flash that will display 4 separate images at the same time when clicked.  I can't get the images to stay on when I take the mouse of the button.  I need the actions script code to make this happen.

    I am trying to create a button in flash that will allow the user to click on the button and 4 separate images show up at the same time.  I can get the images to appear when I click the button but they will not stay on the screen.  I need to know what code I use to make the images stay once the button is clicked, then I need to know exactly where I place that code.  It does not appear to be possible to add the action code to the buttons layer since each time I add a new layer I just get another "up" "over" "down" and "hit" line.
    Thank you in advance
    AP

    It is not clear how you are trying to realize this from your description.  If you are trying to create this within a button symbol it will not work.  Explain your approach and if there is code involved, show what you have so far.

  • I am having a problem trying to get the new version of itunes to download correctly to my laptop. I have updated my ipad to the new ios 7, and windows is showing that it has been downloaded but when I connect my ipad, it is saying I have to download itune

    I really need HELP!!! I have a laptop that runs with windows vista, and I have been having issues trying to get it to download the new version of itunes that would be compatible to the new version of ios 7 that I have already updated on my ipad. I have downloaded this three times, it shows that the download is complete, but when I connect my ipad to my laptop it is still telling me that I have to download the new version again and it will not sync with my ipad until I do. Does anyone else have this issue and can anyone help me figure out how to correct it? I would be most grateful!!

    sign out from the creative cloud and then sign back in
    Sign in, Sign out | Creative Cloud desktop app

  • I have an iPod 2nd gen, trying to get an update so I can add facebook, but it will not update. Current ver is 4.2.1 How do I get it to update?

    I have an iPod 2nd gen . I have been trying to get an update to the software, but it will not update. Current version is 4.2.1 Trying to update it so I can use facebook on it, but with this version facebook will not work. Can someone help  with this please.

    Ipod touch 2 g does not go above ios 4.2.1 and the facebook update needs 4.3 , so there is no way to update the app.

Maybe you are looking for