2 JButtons, both have focus. Why?

Hi
Please take a look at the Programm down there.
Im creating 2 Buttons. Each Button has a reference to the the other one. When i push any Button, i show 2 Messageboxes and give the focus to the other button. After the second Messagebox has been hidden, it looks like that both Button in the Frame have the focus. requestFocus works only once. After the 2nd requestFocus its impossible to change Focus by pressing the tab-key. When i show only 1 Message, everything works fine. Whats the problem?.
thanxx for your help
Kaltenbrunner Siegfried, A
// --- Starting here
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleTest
    public static void main (String args[])
        JFrame frm = new JFrame();
        KButton b1 = new KButton(frm, "Button1");
        KButton b2 = new KButton(frm, "Button2");
        b1.setF(b2);
        b2.setF(b1);
        frm.getContentPane().add(b1, BorderLayout.NORTH);
        frm.getContentPane().add(b2);
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frm.pack();
        frm.setVisible(true);
    private static class KButton extends JButton implements ActionListener
        Frame frm;
        JComponent f;
        KButton(Frame P_frm, String Ps_caption)
            super(Ps_caption);
            setName(Ps_caption);
            addActionListener(this);
            frm = P_frm;
        public void setF (JComponent c)
            f = c;
        public void actionPerformed(ActionEvent e)
            try
                JOptionPane.showMessageDialog(frm, "Message1");
                JOptionPane.showMessageDialog(frm, "Message2");
                f.requestFocus();
            catch (Exception ex)
                ex.printStackTrace();
}

Hi,
Your program is correct, only thing what you were missing I have added that to your code and giving you back. Tell me whether it works as you wanted or not.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleTest
     public static void main (String args[])
          JFrame frm = new JFrame();
          KButton b1 = new KButton(frm, "Button1");
          KButton b2 = new KButton(frm, "Button2");
          b1.setF(b2);
          b2.setF(b1);
          frm.getContentPane().add(b1, BorderLayout.NORTH);
          frm.getContentPane().add(b2);
          frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frm.pack();
          frm.setVisible(true);
     private static class KButton extends JButton implements ActionListener
          Frame frm;
          JComponent f;
          KButton(Frame P_frm, String Ps_caption)
               super(Ps_caption);
               setName(Ps_caption);
               addActionListener(this);
               frm = P_frm;
          public void setF (JComponent c)
               f = c;
          public void actionPerformed(ActionEvent e)
               try
                    /////// Added
                    if(e.getActionCommand().equals("Button1"))
                         JOptionPane.showMessageDialog(frm, "Message1");
                    /////// Added
                    else
                         JOptionPane.showMessageDialog(frm, "Message2");
                    f.requestFocus();
               catch (Exception ex)
                    ex.printStackTrace();
Happy Coding.
Deepak

Similar Messages

  • IOS 5 used to allow Airplay between iPad (WiFi) and Apple TV (Ethernet) as long as they were on the same network. In iOS 6, now both the iPad and the Apple TV have to be on the same network and both have to be connected using WiFi ? Why did they change ?

    iOS 5 used to allow Airplay between iPad (WiFi) and Apple TV (Ethernet) as long as they were on the same network, i.e. connected to the same wired/wireless router. In iOS 6, now both the iPad and the Apple TV have to be on the same network and both have to be connected using WiFi ? Why did they change this ? Means that the iPad and the Apple TV box both have to be in range of the wireless router when this wasn't a restriction before. Apple TV could be anywhere as long as it was connected to the same wireless router via ethernet cable. Seems like an unnecessary thing to restrict.

    I have found with AppleTV that it is the IPV6 on the computer you want to access is the problem.  The issue is that Homegroup on Win 7 or Win 8 requires IPV6 to work, but AppleTV won't work with IPV6.  (So maybe double check you have IPV6 turned off)
    So you have to make a choice - Homegroup or AppleTV.... but you can't have both, until Apple brings ATV up to date. (crazy that it does not recognise IPV6 - c'mon Apple!)
    You can set up sharing individually in Win 7 or 8 and have the ATV access files that way.
    Having said that, there is always the exception.. I have an old HP home server running Win8 and it services ATV - but is part of the Homegroup... have no idea why it works on both, but no other machine on the home network will talk to both ATV and Homegroup at the same time!

  • My iPod will charge in the computer but not my iPod dock, my sisters iPod dock or the wall charger. My sisters iPod will charge in all and we both have the same sofware and generation. Why won't mine charge?

    My Ipod will charge in the computer but noy my iPod dock, my sisters iPod dock or the wall charger. My sisters iPod will charge in all and we both have the same software and generation. Why won't mine charge?

    Look the dock connector on your iPod. Look for abnormalities like bent or corred contacts, foreign material and cracked/broken plastic.
    Try:
    - A reset. Nothing is lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears..
    - Restore from backup
    - Restore to factory settings/new iPod

  • Why does FaceTime keep saying "connection lost" when we both have full bars on our wifi?

    Why does FaceTime keep saying "connection lost" when we both have full bars on our wifi? My friend in Texas has tried to call my via FaceTime but for some reason, every time she does, it keeps saying "connection lost" when we both have full bars on our wifi. Keep in mind, I am from Nebraska so we have the same time zone and I have an iPod 4 while she has a iPhone of some sort but that shouldn't matter because I am still able to FaceTime my friend in California, which is two hours behind me. So, I guess I just want to know why I cannot reach my friend in Texas. Please, someone help me!
    -Mukestina

    Apple has released a document which is reported to address the recent FaceTime issue.
    http://support.apple.com/kb/TS5419

  • My husband I both have iPhone 5.  He can speak his messages but I cannot.  Why not?

    We both have iphone 5 using 7.1OS  When he wants to send a message he has an option to use a mic.  My identical phone does not have this feature.  How can I get it or why don't I have it.

    I would turn Siri off and then Hold down the Sleep/Wake button and the home button together until the Apple logo comes on your screen. Then let both buttons go and wait for phone to restart. Once it comes back on turn siri back on and recheck your messages for the option.

  • I love the 6th Gen. iPod Nano but it has a major deficiency, the power button. I've bought 2 and they both have given me the same issue of the power button becoming slack and not functioning. Why is this so, and how can I fix it??

    MAJOR DEFICIENCY = WASTED MONEY:
    I love the 6th Gen. iPod Nano but it has a major deficiency, the power button. I've bought 2 and they both have given me the same issue of the power button becoming slack and not functioning. Why is this so, and how can I fix it??

    Greetings,
    I've never seen this issue, and I handle many iPads, of all versions. WiFi issues are generally local to the WiFi router - they are not all of the same quality, range, immunity to interference, etc. You have distance, building construction, and the biggie - interference.
    At home, I use Apple routers, and have no issues with any of my WiFi enabled devices, computers, mobile devices, etc - even the lowly PeeCees. I have locations where I have Juniper Networks, as well as Aruba, and a few Netgears - all of them work as they should.
    The cheaper routers, Linksys, D-Link, Seimens home units, and many other no name devices have caused issues of various kinds, and even connectivity.
    I have no idea what Starbucks uses, but I always have a good connection, and I go there nearly every morning and get some work done, as well as play.
    You could try changing channels, 2.4 to 5 Gigs, changing locations of the router. I have had to do all of these at one time or another over the many years that I have been a Network Engineer.
    Good Luck - Cheers,
    M.

  • HT3529 My wife and I both have an iphone.   We initially created it under her apple id.   We will receive each others text messages from certain people not all.   Any ideas why and what we can do to stop it

    My wife and I both have an iphone.  We initially set them up under one apple id account.  When we text sometimes we will receive each others text messages from others.   Example I will text a friend...she will not see my text but the reply comes to both of us.  It seems to be random which ones.  Any ideas how to correct this

    Yup, get your own AppleID.
    The messages that are being sent to both phones are technically not text, they are Apple's iMessage. They use the data part, not the texting part. So if you have an iPad or a Mac computer, you can send/receive the iMessages there too.
    KOT

  • Since years, my wife and I are sharing one Apple computer. On this, we both have an individual user account. Each of us has an own iTunes Account and an own individual media library. Why is this setup now blocked by Apple? Cannot download purchased music.

    Since years, my wife and I are sharing one Apple computer. On this, we both have an individual user account. Each of us has an own iTunes Account and an own individual media library. Each of us is using an own individual iPhone, which we frequently update with our iTunes Accounts. We have had this setup for years. It was convenient, reliable and user friendly, since we both could download what we wanted, create playlists, etc. without impact on the other. Exactly this convenience has made me and my wife real Apple fans, so that we also wanted to convince our daughter to move from Android and PC to our easier Apple setup.
    Since a few weeks, this setup does not work anymore. From Apple Support (online chat on Apple.at) I was not told that this is not supported any more. Every computer is only allowed to be connected to one iTunes account. From one perspective (sharing music across other users as an act or media piracy, etc.) I can somehow understand this. However, since we are using different user accounts on this computer, I do not have access to other user´s iTunes media and could not play, download or copy it. So what is the point in this?
    This now means, that my wife and I are only allowed to download individually purchased music with our personal iTunes accounts only with an interval of 90 days, so every on of us 2 times a year!
    Was I incorrectly informed by the Apple support? If so, how can I solve the problem? Or is this really a new policy by Apple? If so, what is the reason? Am I expected to purchase a Mac for my wife, my daughter, myslef and for the three smaller kids to follow soon?

    Welcome to the Apple Community.
    Unfortunately, if Apple simply allowed people to log into different accounts and download content, everyone would be using everyone could share everyone else's content and bypass the need to purchase anything. To protect against this, they limit you to logging into a new account to once every 90 days.
    If two or more of you, have different accounts and use only one computer, you should each have your own user account on the computer, to avoid the need to log in and out of iTunes.

  • When I use imessage with a friend it shows his email instead of the contact name. also I cant send an imessage to him, why? we both have iphone 4s with IOS 5.0.1

    hope you can help me

    Make sure you both have iMessage turned on in Settings -> Messages.  The Receive At setting on your friend's phone will show how you can reach him/her (just as your setting will show how they can reach you).  Hope this helps!

  • HT204053 why do my husbands iphone and my iphone seem to be synced as when he puts in a new contact it also goes onto my phone if i deleted his it comes off his how can i stop this we both have different apple ids

    not sure how to fix this problem i seem to have synced my iphone and my husbands iphone together as when he deletes a contact from his phone it also comes off mine we both have different itunes account when i add new contact it also goes onto his please help

    Welcome to the Apple community.
    The iTunes and iCloud accounts are different accounts, check that you are not both using the same iCloud account at settings > iCloud.

  • I have a MacBook pro and an IPAD.  My MacBook gets wi fi but my IPAD does not ... and yet both have been connecting to the Internet for four years. Why isn't my IPAD connecting now?

    I have a macbook pro and an ipad ... both have which regularly connected to the web through my airport for two years ... now, my ipad won't connect ... and the genius bar says my ipad is ok. Does anyone have any suggestions as to the cause and the cure?

    Can your iPad connect to other Wi-Fi networks? If so, is it possible that you may have configured your AirPort to restrict access to the iPad by including the iPad's MAC address in the AirPort's Timed Access Control settings?

  • How to listen for key press when air app does not have focus

    Hi,
    I am developing a application in air and part of the functionality I need is the ability for the app to listen for when a specific key is pressed, even when the air app does not have focus.
    Is there support for this for windows or mac? If not, how might this be accomplished? ANE?    

    Ok Mr. Smartass...Ok
    I'm building a browser that is always open, and when
    a user presses Ctrl+F1 (notice, just those two keys,
    I don't care what else they press...) the browser
    will open up. That way, you don't have to wait for it
    to load all the time.You have two ideas here. One is having a universal key map that always gets ctrl-f1 sent to your app. The other is a program that is constantly running so that you don't have to wait for it to open up. The former is not possible (and this is a good thing) As warneria and I have been saying, it is bad design for an app to try to force an OS to implement this kind of feature.
    If you're not going to help please don't post at all;
    it's a waste of time for both you, me, and anyone
    else who may need help on the same subject. Why wouldBelieve it or not, I am helping you.
    See
    http://www.google.com/search?hl=en&lr=&q=programming+code+side+effects
    and
    http://www.faqs.org/docs/artu/ch04s02.html
    "Doug McIlroy's advice to �Do one thing well� is usually interpreted as being about simplicity. But it's also, implicitly and at least as importantly, about orthogonality."
    anyone in their right mind who's trying to steal
    people's passwords come out and say, "I'm not trying
    to steal people's passwords!"wait, your question is why would someone trying to steal passwords say I'm not trying to steal passwords? I think duplicitous people in their right minds might try to trick you that way.
    Beyond that, even if you're not a malicious hacker - and I am sure you are not - if someone posts a solution to your problem, malicious coders then will have learned how to do it. If you think you're programming or using these forums in a bubble, you are not.

  • I'm relatively new to Mac and want to try and get the most out of the new MacBook Air.   My wife and I have been sharing the same Apple ID. We both have iPhones - she has a 5 and I've got a 4S.   We only have one copy of iTunes and we have been sharing t

    I'm relatively new to Mac and want to try and get the most out of the new MacBook Air.
    My wife and I have been sharing the same Apple ID. We both have iPhones - she has a 5 and I've got a 4S.
    We only have one copy of iTunes and we have been sharing the account. (She doesn't really use the computer for anything beyond writing the odd weekend assignment.)
    Would I be better off setting her up with her own and making her as a separate user on the computer? Would this require much work?
    In recent times with updates, we have a few problems with the duplication of texts and that sort of thing. Both of our texts are stored on the computer and that sort of thing. Also, sometimes texts I send her are sent through to me  from her, if that makes any sense.
    Anyway, I don't really want to overly complicate matters when it comes to accounts etc, but I wanted to know if a fresh Apple ID would be the best thing or even a new user?
    Any tips etc would be greatly appreciated
    Thanks in advance
    MacBook
    I have this question too (0) Reply

    Your question is almost too much a personal one, begging the question "do we (husband and wife) feel comfy sharing one account on the Mac"   maybe thats why nobody answered you.
    It doesnt complicate anything, but it adds steps for switching accounts on the Mac/ purchases etc. of course
    since your question is mostly personal, ..I wont answer THAT part of it, but creating a new account is easy.....messing with switching back and forth is also a personal preference 'issue' as well.   I prefer to keep things simple, but...........you and yours,  I dont know.......
    http://support.apple.com/kb/PH11468

  • Only one of my earbuds on my bose headphones works with my ipad, iphone and macbook- if I hold them there the right earbud will work, but for the life of me, I can't get them to both work. Why is this? And is Apple doing anything about this?

    Only one of my earbuds on my bose headphones works with my ipad, iphone and macbook- if I hold them there the right earbud will work, but for the life of me, I can't get them to both work. Why is this? And is Apple doing anything about this? While Apple's headphones have (finally) admittedly gotten better of late, I still prefer the much more comfortable headphones & sound quality that Bose makes and that I spent the money for.

    Bose Product Support

  • HT201077 My wife and I BOTH want to contribute to the same "family" photostream album. We both have  our own iPhones. Is there a for both of us to contribute to the same album from our respective iPhones that we can then share with everyone?

    My wife and I BOTH want to contribute to the same “family" photostream album. We both have  our own iPhones. Is there a for both of us to contribute to the same album from our respective iPhones that we can then share with everyone?

    Your question is almost too much a personal one, begging the question "do we (husband and wife) feel comfy sharing one account on the Mac"   maybe thats why nobody answered you.
    It doesnt complicate anything, but it adds steps for switching accounts on the Mac/ purchases etc. of course
    since your question is mostly personal, ..I wont answer THAT part of it, but creating a new account is easy.....messing with switching back and forth is also a personal preference 'issue' as well.   I prefer to keep things simple, but...........you and yours,  I dont know.......
    http://support.apple.com/kb/PH11468

Maybe you are looking for

  • "E_ADEPT_REQUEST_REPLAY" Error in Packaging a PDF file

    Hi Jim, As per ContentServer_Technical_Reference.pdf (page no 9) I passed <filename>, <location> and <src> parameter in our packaging request xml. File is packaging successfully and service is also placing the encrypted file to new location listed in

  • Plugged in, not charging - PLEASE HELP

    Hi, I have a T61 and from yesterday my battery is not charging. I have a 9 cell battery and when I plug in the AC adapter, it shows "plugged in, not charging" status on the battery icon in the system tray. Could someone please help asap? Thanks, Anim

  • Like ot change the View of F110 (Payment proposal)

    Hi The veiw of the payment proposal using Tcode F110 is stamdatd as attached. and i would like to change this like as  ALV Grid ..Please suggest how can i change the same.

  • Creating Segment for a zIdoc

    Hi All, I want to create a segment in an Idoc. Shall I create database structure after creating the SEGMENT structure? First of all I want to create all the Segment structures and then I want to create structures in SE11. Please let me know shall I c

  • How do I resolve an error when installing iOS 4.3.5?

    When I try to update to iOS 4.3.5, I get an error that states my phone is not the required build. I have a white iPhone 4. I had restored and reset all the settings as well as erased the contents of the phone. Help!