Problem disabling JButton in ActionListener after setText of JLabel

What i want is when i click View to see the label say "Viewing ..." and in the same time the btnView (View Button) to be disabled.
I want the same with the other 2 buttons.
My problem is in ActionListener of the button. It only half works.
I cannot disable (setEnabled(false)) the button after it is pressed and showing the JLabel.
The code i cannot run is the 3 buttons setEnabled (2 in comments).
Any light?
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class BTester extends JFrame implements ActionListener { 
     JButton btnView, btnBook, btnSearch;
     BTester(){     //Constructor
          JPanel p = new JPanel();
     JButton btnView = new JButton( "View" );
     btnView.setActionCommand( "View" );
     btnView.addActionListener(this);
     JButton btnBook = new JButton( "Book" );
     btnBook.setActionCommand( "Book" );
     btnBook.addActionListener(this);
     JButton btnSearch = new JButton( "Search" );
     btnSearch.setActionCommand( "Search" );
     btnSearch.addActionListener(this);
     p.add(btnView);
     p.add(btnBook);
     p.add(btnSearch);
     getContentPane().add(show, "North"); //put text up
getContentPane().add(p, "South"); //put panel of buttons down
setSize(400,200);
setVisible(true);
setTitle("INITIAL BUTTON TESTER");
show.setFont(new Font("Tahoma",Font.BOLD,20));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
     //actionPerformed implemented (overrided)
     public void actionPerformed( ActionEvent ae) {
String actionName = ae.getActionCommand().trim();
if( actionName.equals( "View" ) ) {
show.setText("Viewing ...");
     btnView.setEnabled(false); // The line of problem
//btnBook.setEnabled(true);
//btnSearch.setEnabled(true);
else if( actionName.equals( "Book" ) ) {
show.setText("Booking ...");
//btnView.setEnabled(true);
//btnBook.setEnabled(false);
//btnSearch.setEnabled(true);
else if( actionName.equals( "Search" ) ) {
show.setText("Searching ...");
//btnView.setEnabled(true);
//btnBook.setEnabled(true);
//btnSearch.setEnabled(false);
} //end actionPerformed
     private JLabel show = new JLabel( "Press a button ... " );
public static void main(String[] args) { 
     new BTester();
} // End BTester class

1. Use code formatting when posting code.
2. You have a Null Pointer Exception since in your constructor you create the JButtons and assign them to a local variable instead of the class member.
Change this
JButton btnView = new JButton( "View" );to:
btnView = new JButton( "View" );

Similar Messages

  • Problems with your HP printer after upgrading to Windows 8.1

    If you are experiencing problems with your HP printer after upgrading to Windows 8.1 please click on the below link and install the HP Print and Scan Doctor and run the utility to fix the issue.
    www.hp.com/go/tools.
    I was an HP employee
    If I have helped you solve your issue please mark it as solved
    **Say Thanks By Clicking on the Kudos Star**

    Hi.....my laserjet 1536dnf mfp was working perfectly with win 8 pro....then I installed win 8.1 pro and now the computer ,which is part of a network,can not communicate with the scanner of the printer--it prints just fine. On another computer (running win 7 ) on the same network, the scanner and all other printer functions  work just fine.
          I have tried installing the latest drivers from HP......scanner still not "communicating" with computer.....also temporarily disabled firewall.....please help...all the best -David G (gossat)

  • Problem Disabling Beats Audio w/ Windows 10

    Hi - I have  problem with Beats Audio Control Panel after upgrade windows 8 .1 to windows 10. I updated the audio drivers which didn't solve the problem.
     Product Name: Hp Pavilion dv7-7051swProduct Number:  B6G49EA#AKD Driver Versions:IDT High Definition Audio CODEC - 6.10.6491.0
    Intel(R) Display Audio Driver   - 6.16.0.3154NVIDIA Virtual Audio Driver   - 1.2.30.0 I tried also reinstall this driver but it didn't help.
     It's propapbly the same issue as here:http://h30434.www3.hp.com/t5/Notebook-PC-Sound-and-Audio/Problem-Disabling-Beats-Audio-w-Windows-8-1/m-p/3208867#M43609  Thanks for any help.DMaster

    Hey, I had the same problem as you and solved it. Product Name: HP ENVY 15 Notebook PC
    Product Number: J0C48EA#AB9
    OS: Windows 10 Home 64-bit While using Windows 8.1, what I did to disable the Beats Audio Control Panel was to update the driver to the generic High Definition Audio, as this guy shows:
    https://goo.gl/0XN7Nl When I upgraded from Windows 8.1 to Windows 10, the new OS started using the IDT driver, enabling the Beats Audio Control Panel.
    I've tried to do the same under Windows 10 but there was Generic Audio Driver a.k.a. High Definition Audio Driver available. This is what I did:
    1. Download, install the High Definition Audio Tool from Microsoft Hardware Dev Center, and restart your PC. This is the generic audio driver that was missing:
    http://download.microsoft.com/download/4/8/D/48D7ED36-832B-41D7-AE0A-04AD7D8CA837/HdauSetup_x64.msi
    https://msdn.microsoft.com/en-us/library/windows/hardware/Dn613936(v=VS.85).aspx 2. Open Device Manager -> Sound, video and game controllers
     3. Righ Click Menu over IDT High Definition Audio CODEC and select Update Driver Software
     4. Choose Browse my computer for driver software
     5. Choose Let me pick from a list of device drivers on my computer
     6. Choose High Definition Audio Device
     7. Select Yes in the Update Driver Warning 8. The High Definition Audio Codec is installed and the Beats Audio Control Panel disabled Now I can hear all my music again without the awful Beats Audio effects and volume variations that are a nag.
    Hope this helps you out. Thank you. hitek81 

  • Why does a VRRP master with preemption disabled regain master state after the reboot ?

    Q: Why does a VRRP master with preemption disabled regain master state after the reboot?
    A: This issue is found in the following scenarios:
    1. When spanning tree is disabled on either of the VRRP controllers but enabled on upstream switch(es).
    2. When the controller(any one VRRP controller) and upstream device(s) run different versions of STP.
    3. STP convergence time is different across the VRRP controllers.
    In these scenarios, rebooted vrrp master is expected to come back as vrrp MASTER as the link takes some time to converge and fail to receive VRRP advertisement packets from its peer and may roll back to MASTER.
    Trigger for this is, since STP is enabled on intermediate switch and disabled on controller, switch is taking some time ~30 secs to converge the link while port on the controller has become UP and fail-over to Master due to 
    not receiving VRRP advertisement packets
    In all these cases, it is advised to enable holdtime to mitigate issue. Holdtime has been introduced to tackle this issue in the "preemption disabled scenario".
    Configuration via CLI:
    (controller) (config) #vrrp <id>
    (controller) (config-vrrp)#holdtime
    Description:
    The VRRP virtual router does not begin listening to advertisements until the holdtime expires. If your deployment includes a VRRP master with preemption disabled and an uplink switch is running RSTP, a higher value will prevent the VRRP master from regaining the master state after it reboots.
    Range: 30 - 120 seconds
    Default: 45 seconds

    Hey Jim,
    Thanks for the follow-up.  Here are some more details:
    OS - 10.8.2
    FCP X - 10.0.7
    I can't update either of these because of my Avid installation.
    Something else I didn't mention – this happens in a 4K project.  Notice how a default Zoom title looks:
    Lines 1 and 2 are almost stacked on top of each other.
    Here's my title style:
    Here's what the title looks after I apply the title style, modify Line 1, and remove the contents of Line 2:
    And here's how it looks in the exported master file MOV:
    Notice how it's pushed down?
    Then I decided to make a 720p project.  No more title problems.
    So if you have some 4K footage, Jim, give it a go.  Or if there's another 4K-er out there, try this and let me know.
    Thanks!

  • Having problems with Bridge shutting down after saving photo in PS Cs5,,,,,,,,,  Also when i attempt to update either PS or bridge get an error message in Adobe application manger "Error loading updater workflow"

    Having problems with Bridge shutting down after saving photo in PS Cs5,,,,,,,,,  Also when i attempt to update either PS or bridge get an error message in Adobe application manger "Error loading updater workflow"

    Sorry for the late reply. My email firewall has become a little over zealous & sent a lot of my emails straight to my junk email folder, so I have only just now discovered your reply in my junk mail folder.
    The only "don't open files exceeding xxx megabytes" instruction I can find in my Prefs, is in the Bridge Prefs for Thumbnails, & mine is set at 1000mb. The biggest files I handle are bigger than 200mb so I should be able to open a few, not just one.
    However, this doesn't explain why I can open a psd format file of 180mb, close it, but then can't open a RAW format file of only 26mb immediately after.
    I can open the RAW file only if I restart my computer - very annoying!
    However, thanks for the advice about the video card & memory.
    So, I'm still stuck as to what the issue is.

  • Problem with Rescue and Recovery after installing Norton Internet Security 2010

    Hi all.
    It's my first time in this forum.
    I have a problem, with Rescue and Recovery, after installing Norton Internet Security 2010 on my T43.
    The message I get it:
    "Rescue and Recovery is unable to back up the file 'C:\Documents and settings\all Users\Application Data\ Norton\ 00000082\00000109\000003c1\cltMLS1.bat' Because the file is either corrupted or being used by another application. Please close any application that could be using the file.
    I tried to close the Norton but I couldn't find how.
    Tanks
    Doron71

    Hi and welcome to the forum,
    the reason for this situation is, that the antivir files are protected from being modified.
    This is the reason, why this file cannot be backed up. I assume, that you would get much more such messages, as there are surelly multiple files files, that are protected like this.
    So the solution is to block folders from being archived. Please start RnR application and in the configuration set this folder as the excluded one.
    This will skip the backup of this file and will fix your situation.
    Please let me know, if you have covered this.
    Cheers

  • Problem with Facebook and instagram after istalling iOS 7.1. Can not open them!

    Problem with Facebook and instagram after istalling iOS 7.1. Can not open them!

    Hi Hanjon!
    Here is an article that will help you troubleshoot these purchased apps:
    iOS: An app you installed unexpectedly quits, stops responding, or won’t open
    http://support.apple.com/kb/ts1702
    Thanks for being a part of the Apple Support Communities!
    Regards,
    Braden

  • Problem with flash on IE11 after using adobe cleaner

    Problem with flash on IE11 after using adobe cleaner to remove a trial version of photoshop because there was not any entry on add/remove applications in windows 8.1
    Its to frustrating to reinstall everything. I tried everything from your support page with no luck…

    Link for Download & Install & Setup & Activation problems may help
    -Online Chat http://www.adobe.com/support/download-install/supportinfo/

  • I have just updated to Yosemite, but now I can't get the custom shortkeys to work. In Mavericks I had no problem whatsoever, but now even after googeling and restart no solution. Does anyone have the problem? All the other shortcuts work!

    I have just updated to Yosemite, but now I can't get the custom short-keys to work.
    In Mavericks I had no problem whatsoever, but now even after googeling and restart no solution.
    Does anyone have the problem? All the other shortcuts work!

    Hi Thomas,
    I can confirm the problem you are hitting. The XML test trace does not get recognized at all, and it defaults to Eclipse's basic Open File behaviour. I am not sure if it's because the format definition is missing, or if it's because something prevents the trace type from being recognized. I will open a bug about it.
    Thanks for identifying this issue!
    In the meantime, if you'd like to experiment with XML analyses, you can also take a look at the example at https://github.com/tracecompass/xml-analysis-example .
    Cheers,
    Alex

  • I am having problems with my music collection, after burning all of my music to the computer I organized it into folders and placed it in the iTunes Folder. Starting on a new computer now. I can get my music from old computer?

    I am having problems with my music collection, after burning all of my music to the computer I organized it into folders and placed it in the iTunes Folder. As of now i realize this was a mistake. Starting on a new computer now. I cant get my music to transfer from the itunes folder on the old computer? I keep getting error "Can't Read from the source file or disk." Whenever I got to folder properties its always checked read only. But when i play the song it works just fine. Im sure this is just because I added music into itunes folder but is there anyway to fix it?

    WMA files are 'window media audio' files, which is a Microsoft format. If you want to add them to your iTunes library on your Mac then you will need to convert them into a compatible format first. If you still have your windows machine then iTunes for Windows can convert them from WMA to MP3 format : https://discussions.apple.com/message/24158701#24158701
    Or try a search for, for example, 'convert wma to mp3' to find programs to convert them.

  • My iPhone 4 with iOS 6 is making me start to hate Apple. Any App and at any time I open and I can not view it or move for more than 2 minutes, they close themselves. During connections, it also gives this problem and the signal disappears after a few seco

    My iPhone 4 with iOS 6 is making me start to hate Apple. Any App and at any time I open and I can not view it or move for more than 2 minutes, they close themselves. During connections, it also gives this problem and the signal disappears after a few seconds back but often the person on the other end has hung up ... I can not stand it anymore, someone suggests something?
    Besides these problems, there is the battery, which was bad got worse, she is not lasting more than 10 hours, even without using the phone.
    Sometimes it even seems that the problem was solved, but my joy did not last long after I celebrate all the problems return, is incredible ...
    thanks.
    Sorry my bad Inglês.

    Try a reset hold home/sleep buttons until Apple logo appears
    If that does not improve try a restore
    http://support.apple.com/kb/HT4137
    For your information
    We are NOT Apple here we are all users helping other users
    so emotion is ignored

  • Anyone having same problem? I phone 4 after updating to Vers.5.1.1. battery cannot be 100% full charge, always stop at 99% and battery drains off fast too :(

    Anyone having same problem? I phone 4 after updating to Vers.5.1.1. battery cannot be 100% full charge, always stop at 99% and battery drains off fast too

    I had major issues with the iPhone 4s battery, however it’s resolved.
    The tech who set the phone up at the Apple store did so with little training.
    if you have a mobile me account. First go and move all your data to the cloud by going on your computer and logging in at me.com/move. The cloud has replaced mobile me, so there is no need for those two accounts
    Also make sure that for any of your email accounts you set them up to fetch, not push. My tech person set them all to have the email servers push data to the phone. The new iphone4s antenna is extremely strong so it will continually try to access stuff that is pushed–***** a lot of battery life doing this. It makes it worse if you have exchange 2010 accounts. Something about changes made to exchange really suck battery life from devices that access such accounts.
    turning of locator and the push notifications from facebook--they have a lot!

  • How im suppose to fix the auto shutdown problem in my iphone 3gs after updating to ios 5.1.1 this problem has made me a mobile ****** in my house and an loser in thing care so if any solution to this problem let me know

    how im suppose to fix the auto shutdown problem in my iphone 3gs after updating to ios 5.1.1 this problem has made me a mobile ****** in my house and an loser in thing care so if any solution to this problem let me know

    What "auto shutdown problem" are you talking about?

  • Problems with wi-fi connection after waking up from sleep

    Hey,
    I have MacBook Pro 13 (early 2011), MacOsX 10.7.2.
    I've got a problem - when I wake up after sleep my internet connection doesn't work for half a minute, may be more. I do diagnostics and it says that connection is ok, but still don't work. I've tried to do something with energy saving settings, but i didn't success.
    What is important: I didn't have such a problem previously. I think it appeared after one of software updates. I can even remember, there was an updated with description, saying that t fixes the problem of internet connections after Mac wakes up after sleep...
    How can I solve this problem?

    I have the same exact problem and it is caused by the latest ETI or whatever update it is. - the one that required restart of my computer. For me it takes multiple times to turn wifi on and off on my macbook pro before the internet starts working. Someone please help. Apparently reinstalling Mac Os X 10.7.2. should help but I'm not sure if I want to drop my mbp at apple store for 2 days yet again.

  • Problems with wireless mouse/keyboard after upgrade to snow leopard

    Hi!
    I am wondering if someone has some insight for me.  I recently upgraded to Snow Leopard from Tiger. I have been using a Logitech S 530 wireless keyboard/mouse combo for a few years.  I am now having problems with them irratically.
    1. When on line and the page is large, I often cannot move the blue bar at the bottom of the screen to scroll to the right. What happens is like a stutter; as I am dragging the bar, it and the page shake rapidly side-to-side. Sometimes, I can drag it to the right, but as soon as I let go, it snaps back to the left.  This does not happen in Word.
    2. When in boxes with dropdown options, only occasionally does that happen.  The dropdown either doesn't show, or it flashes quickly.  Sometimes it will work after clicking many times. This happens with dropdown menus as well as search boxes that have dropdown choices for previous searches or suggested searches a la Google.
    3. When I use my function key or mouse to display all windows, I can't choose the one I want.  Regardless of which one I put my cursor over, only the left-most one is highlighted and comes to the front when I click.
    4. There is a varying lag. Sometimes the system is responsive, and other times there is a lag of varying lengths before the system responds to the mouse action (click, drag, zoom, etc.)
    5. For a while, my left mouse button wouldn't work.  I reconfigured it, that seems to have done the trick.
    6. Today, I can't open any of the menu items on Firefox.  I can move the cursor there, but when I click on any of them, nothing happens. This is okay in Safari.
    I have disconnected and reconnected the usb, restarted the computer, and tried to reinstall the software for the mouse and keybord. When I did that, I got a message saying it couldn't install on the current OS, so I went to Logitech and dowloaded and installed the latest version (which indicated it is for OS X 10.6.8.)
    I don't know if this is a Snow Leopard problem, but it started sometime after I upgraded.  Thanks in advance for any help!
    Donna

    Update all your third party software  or uninstall and reinstall 10.6 versions.
    If your going to 10.7, be warned a lot of software will not work at all and your 10.5 era machine will be slow, perhaps even have problems as 10.7 is problematic on older hardware.
    http://roaringapps.com/apps:table
    IMO save for a new 10.8 machine after this summer.
    See #1-15 here, tune yourself up good.
     Step by Step to fix your Mac

Maybe you are looking for

  • RFC Sender ---- R/3(RFC) - XI- File.

    Hi All,    I need some clarification on this weblog for configuring TCP/IP connection /people/michal.krawczyk2/blog/2005/03/29/configuring-the-sender-rfc-adapter--step-by-step Please open this web log and in that in 4th and 5th points ..I am having d

  • Purchased TV Shows disappeared before loading.

    I'm out $22! I purchased the first season of Saturday Night Live (13 shows of it anyway) and started to download. Process was VERY slow. Began manually selecting one episode at a time. This was working. I needed to leave and my husband figured it was

  • SQL log file

    Hi guys. I know this is not adapted for this forum, but could anybody show me a way to read SQL server log(.ldf) files. have already tried SQL log Rescue, Apex SQL. I am trying to read a log file that got muh bigger in a couple of days. These 2 softw

  • Bugs due to case sensitivity of objects?!

    Hi, When migrating from MSAccess 97 to Oracle 8i, it seems that there are many problems during the migration due to case sensitivity of Oracle objects. Specifically, the usage of the double quoted is not always correct resulting in JET/DAO 3011 messa

  • Problem after last xorg update

    I started getting this after the last xorg (2.16.0-1) (1.11.1-2) updates [ 1395.736] (II) UnloadModule: "evdev" [ 1395.736] (II) Unloading evdev [ 1395.737] Backtrace: [ 1395.737] 0: /usr/bin/X (xorg_backtrace+0x37) [0x81c00a7] [ 1395.737] 1: /usr/bi