Can't change the CardLayout.

Sorry, can someone help me with this code. I can't change the cardlayout when i try to seperate the JButton and the cardLayout. However, when i try it in one class, there is no problem. Can help me with this and give me some advise? I am learning how to seperate to classes so that the code will not look so messy. Is this the correct way of doing?
/**********This is the main class*************/
import javax.swing.*;
import java.awt.*;
public class PlayCard extends JFrame
     NorthConsole nc = new NorthConsole();
     ChangingCard cc = new ChangingCard();
     JFrame f1;
     JPanel mainPanel = new JPanel();
     public PlayCard()
          f1 = new JFrame("Card Panel");
          f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f1.setSize(400,200);
          mainPanel.setLayout(new BorderLayout());
          mainPanel.add(nc.northCard(),BorderLayout.NORTH);
          mainPanel.add(cc.cardPanel(),BorderLayout.SOUTH);
          f1.getContentPane().add(mainPanel);
          f1.setVisible(true);
     public static void main(String[] args)
          PlayCard pc = new PlayCard();
/*********This is the Panel that contain the button that does the changing*****/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class NorthConsole implements ActionListener
     JButton b3 = new JButton("Display card 1");     
     JButton b4 = new JButton("Display card 2");     
     ChangingCard ch = new ChangingCard();
     JPanel northCard()
          JPanel nc1 = new JPanel();
          b3.addActionListener(this);
          b4.addActionListener(this);     
          nc1.add(b3);
          nc1.add(b4);
          return nc1;
     public void actionPerformed(ActionEvent f)
          ch.getCard();
          Object source = f.getSource();
          if(source==b3)
               ch.displayShow1();
          }//end of b1 action
          if(source==b4)
               ch.displayShow2();     
          }//end of b2 action
}//end of class
/************This is the CardLayout Class******************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ChangingCard
     String card1But = "Panel 1 with Button 1";
     String card2But = "Panel 2 with Button 2";
     JButton b1 = new JButton("Card 1");
     JButton b2 = new JButton("Card 2");
     JPanel cMain = new JPanel(new CardLayout());
     JPanel c1 = new JPanel();
     JPanel c2 = new JPanel();
     CardLayout cl;
     JPanel cardPanel()
          c1.add(b1);
          c2.add(b2);
          cMain.add(c1,card1But);     
          cMain.add(c2,card2But);
          return cMain;
     public CardLayout getCard()
          cl = (CardLayout)(cMain.getLayout());
          return cl;
     public void displayShow1()
          getCard().show(cMain,card1But);
          System.out.println("Hello");     
     public void displayShow2()
          getCard().show(cMain,card2But);
          System.out.println("Hello2");
}

try it this way
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class PlayCard extends JFrame
  ChangingCard cc = new ChangingCard();
  NorthConsole nc = new NorthConsole(cc);
  public PlayCard()
    setTitle("Card Panel");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(400,200);
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(nc,BorderLayout.NORTH);
    mainPanel.add(cc,BorderLayout.SOUTH);
    getContentPane().add(mainPanel);
  public static void main(String[] args){new PlayCard().setVisible(true);}
class NorthConsole extends JPanel
  ChangingCard cc;
  public NorthConsole(ChangingCard c)
    cc = c;
    final JButton b3 = new JButton("Display card 1");
    b3.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent f){
        cc.displayShow1();}});
    JButton b4 = new JButton("Display card 2");
    b4.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent f){
        cc.displayShow2();}});
    add(b3);
    add(b4);
class ChangingCard extends JPanel
  String card1But = "Panel 1 with Button 1";
  String card2But = "Panel 2 with Button 2";
  CardLayout cl;
  public ChangingCard()
    cl = new CardLayout();
    setLayout(cl);
    JPanel c1 = new JPanel();
    c1.add(new JButton("Card 1"));
    JPanel c2 = new JPanel();
    c2.add(new JButton("Card 2"));
    add(card1But,c1);
    add(card2But,c2);
  public void displayShow1(){cl.show(this,card1But);}
  public void displayShow2(){cl.show(this,card2But);}
}

Similar Messages

  • HT5312 I DO remember them but Apple chose to put them in Japanese and I can not change the language on Manage my Apple ID so I do not know if I made an error ,it threw me off , it was the wrong question Where did you fly to on your first Aiplane trip ? th

    I DO remember them but Apple chose to put them in Japanese and I can not change the language on Manage my Apple ID so I do not know if I made an error ,it threw me off , it was the wrong question Where did you fly to on your first Aiplane trip ? then I was unable to enter until 8 hours then called Apple Japan 4 times each time threy asked me would you like to speak with an English speaker,I said yes then they told me sorry today is Sunday no English speakers ,but they refused to speak Japanese, then I called 5th time and a kind guy could speak English we were on 1and 1/2 hours he got me to log in but the reset key chain could not be completed still pending.
    He said do not mess with that ! then I got a text from somewhere to reset 4 pins suddenly it was very strange I said to him that I got this pin this morning but it said you can use maximum 3 hours it had a UK number and I told him I do not like this and will not enter the code he said do not do it if it is from the UK and then I said to him ok you did a lot to help but we can not go any further ! and we cut of I went back to my computer to re do the ID but I found everything a mess so I call and a stupid sounding Japanese women with a squeaky voice came on I was calm at first and they want your phone number your IMEI number your iPhone serial number date of birth Address email address it takes 10 munutes to check then they ask what are you caling about so I try to explain my keychain is broken or problems with language security questions and can not change my pasword because the security question have failed me so it is ONE BIG HEADACHE AND I START I GET STRESSED she says Do want an ENGLISH speaker ,I say yes ,that guy i talked to earlier but I never got his name and first time I ever talked to him but they said he is not here so I said ok and then she said today is sunday so call back in the morning ,I said ,well ok in Japanese but they make you feel stupid because they do not want to speak Jap@anese with none natives and they are to busy,And they feel that I should not bother them ,then I say that Apple Japan is trying to refuse Apple foreign customers and then she wants to hang up and ask me to visit the shop ,but they are the same I have a very bad time with Apple Japan since they do not discuss software problems or security with customer meaning if you have a problem they ask you to come on a time 20 minutes max so they do hardware test and say you phone is fine then I say no I can not reset my ID they say you must call call centre so I am going around in circles ,When I call English it is usually Australia so if my problem is in Japan surely if do not want me to talk to them in Japanese and they ask me to call Australia but every time my call charge is expensive after asking them is this free because I have Apple care they say yes but when the call goes to Australia 0120 277 535 it might change to paid call so I call then I have to ask is this charging they say we can not give you that information ! so what can I do I have have been at the computer and phone all day on my day off work and in tre week I am so busy and can not use my phone I can not work without it ,this new technology for you ,they can not cope with the fact that the customer have problems yet they do not want to deal with us because they can not solve it and so it shows them to be useless they like to walk around in their cool tee shirts and retro shop but when it comes to functionality we are unwelcome they got the money so do not return because apple is perfect that nothing should go wrong .
    But it does somehow my English security answers do not work on a Japanese Question especialy if I did not choose that question I set  up the multiple choice In English and wrote the answers in English or Roman and set them langauge preferences in English, do you really think you can correctly write english name or word in Japanese they write a police patrol car  pato caa パトカア they do not have r and l .So it is my choice to make my security easy for me and as difficult for others to hack.But they also have patororoo choo meaning ' now patrolling ' so why they have pato caa patrol car and patoro patrol and have thousands of Chinese words kanji they can find patrol.
    I am getting off the topic but I am at a loss to fix this problem when they hold the keys and i have all the info to verify my ID.

    You have to enter the Apple ID and password. You are running into the Activation Lock
    iCloud: Find My iPhone Activation Lock in iOS 7
    Is there a way to find my Apple ID Name if I can't remember it?
    Yes. Visit My Apple ID and click Find your Apple ID. See Finding your Apple ID if you'd like more information.
    How do I change or recover a forgotten Apple ID Password?
    If you've forgotten your Apple ID Password or want to change it, go to My Apple ID and follow the instructions. SeeChanging your Apple ID password if you'd like more information.

  • How can I change the display of Inbox in my iPad's mail app- so that it takes up the full screen?

    How can I change the display of Inbox in my iPad's mail app- so that it takes up the whole screen, as opposed to just about one third; the other two thirds display the full text of the selected email?

    You can't change the display in the Mail app, if you are holding the iPad in landscape orientation then the left-hand third will be for navigation, and the right-hand two-thirds will be an email. If you hold the iPad in portrait orientation then the navigation section becomes a drop-down section.

  • How can I change the age associated with my daughter's account?

    OK I am sure that this is a common issue.  Back when my daughter was about 9 or 10 years old, we bought her an iPod Touch.   She was too young to have an AppleID of her own, so I set one up for her using an extra gmail accoun that I had, and entered my birthdate/age.  A few years later, she received an iPad, and most recently, an iPhone.   All of these devices are tied to the same AppleID.
    Well, now she will be 13 years old soon, and I would like to switch things to represent reality.  She has her own email account, and I believe you can go to My Apple Id to change the Apple ID name and e-mail address.  My question is, can we change the age associated with the account?
    I hear you saying, "Just create a new AppleID for her."  That may end up being the only solution, but I am trying to avoid having two AppleIDs for her to keep up with.  She has already purchased a fair amount of content (music and apps) under the existing AppleID, and I am pretty sure from looking at the posts on this Community that you can not transfer content away from the AppleID under which it was downloaded/purchased.  And so, if I create a new AppleID, she will have to re-purchase the content to get it all in one place.  As she eventually grows up and becomes independent, I would like for he to not have to "start over" with her AppleID.
    Any advice or direction to information would be appreciated.

    I have a similar situation however a bit more complicated! It seems that when I was setting the birthdate I forgot to change the year so now my seven years old daughter shows up as a two months old! There is no way to change the birthdate because it shows up in light grey when I login into my daughters account and doesn't allow a change! The birthdate can be changed only when the child turns 13 however according to this she will have to be 20 before she can change it to show property 13 and here is where this is getting completely out of hand! Now to make things more complicated I have twin daughters and they came up with their unique but similar Apple ID, so changing one will require to change both Apple IDs! After being on the phone with Apple's customer support for about one hour I talked to a supervisor and the supervisor of the supervisor and their only solution is to create a new Apple ID! Of course in my case I will have to create two new Apple IDs, and I'm considering doing it. However when I started reading it becomes more complicated because I already made their Apple IDs part of my family group. It seems like you're not able to just let go of family member that is less than 13 years of age. You can only transfer it to another family, so Apple is making sure there are no kids left behind It seems like the only option will be to "abandon" the family and then create a new family with the new Apple IDs. If all this sounds bizarre to you it sounds bizarre to me too! If I can just put the kids in the car and drive them to the nearest one hour away Apple Store and have them show their credentials confirming their birthdate I would rather do that than having to spend more and more time with this issue, but that was not an option pointed out by customer support. So folks keep in mind that if you make a mistake your children's age is set in stone until he or she turns 20 if they happen to be seven at the time you made the mistake and no one can change this, even Apple! Now on the positive side I'm glad I didn't do the mistake when she was 13 or she will have to wait until she's 26 Most likely I'll be calling customer support tomorrow again and I will let you know how it went!

  • How can I change the background of a running webpage on my own. Example Facebook I want to change its backround color from white to black just in my view not for all

    How can I change the background of a running webpage on my own. Example Facebook I want to change its background color from white to black just in my view, not for all. Cause I really hate some site with white background because as I read for an hour it aches my eyes but not on those with darker background color.

    You can use the NoSquint extension to set font sizes (text/page zoom) and text colors on web pages.
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • I can not change the time in activity Appointment in WebUi

    Dear Experts!
    I can not change the time in activity Appointment when creating: calendar -> month -> click on the day
    snapshot of problem:
    http://imglink.ru/show-image.php?id=e7a096115a6371ffab46c701f8e470ba
    When I create a Appointment (Activities -> Create Appointment) of all good:
    http://imglink.ru/show-image.php?id=ef65a38bdf7fc77eb9a71ec5c3ad5603
    Help me this problem?

    You need to add that attribute using the config tool for your view configuration. Select the attribute All Day from the context node BTDATE in the available fields to your display field and then save it. It should now be visible in your UI and now you can select or uncheck it to make the time field enable. Check the below image
    http://imglink.ru/show-image.php?id=a9a660778c0fee2b3fd7409d620eddc5
    Regards,
    Shobhit

  • HT201361 Is it possible to save the screenshot files to a different folder than desktop. How can I change the folder?

    Is it possible to save the screenshot files to a different folder than desktop (that is the default). How can I change the destination folder? Thank you, Sal

    To change the screenshot capture location to a new place on your Mac, first think of a location that would serve you properly. We like to place ours in a "Screenshot" folder located inside of the User's "Pictures" folder. To change the location to this new location, open the Terminal and enter the following command:
    defaults write com.apple.screencapture location /Users/[u]/Pictures/Screenshots/
    Replace "[u]" with the name of the user on your system. Once you have entered this command, let's restart the screen capture utility by restarting the SystemUIServer by entering the following command:
    killall SystemUIServer
    You can optionally log out and back in instead of entering this second command, thus restarting the SystemUIServer. Once restarted, all screen captures taken from here on out will end up in your /Pictures/Screenshots/ folder in the User's home folder on your Mac.

  • How can I change the default apple ID for app store. I bought the macbook from my school when I left and I'm the ID in place of mine is the computer departments one. How can i change it to mine?? Thanks

    How can I change the default apple ID for app store. I bought the macbook from my school when I left and I'm the ID in place of mine is the computer departments one. How can i change it to mine?? Thanks

    http://support.apple.com/kb/ht5621

  • FAQ: UI - How can I change the color theme, size of the text, or turn off the application frame?

    CHANGING THE INTERFACE COLOR SCHEME:
    The Photoshop CS6 default interface is dark, but if you prefer the lighter interface you are used to from earlier versions,
    you can change it back in the appearance area. There are 4 default color themes.
    Mac          Photoshop > Preferences > Interface
    Windows   Edit > Preferences > Interface
    CONFIGURING LARGER FONTS:
    For those who need larger fonts, you can also change the UI Font Size down in the type area.
    Be sure to restart Photoshop to see the changes.
    TURNING OFF THE APPLICATION FRAME
    CS6 opens now by default in "Application Frame". You can go Window>Application Frame in the main meu and uncheck this

    Select the title / text and then click on the "i" (inspector). A colored pin wheel shows up after you click on the square box directly below the font settings inside the inspector window. Then simply drag the dot to the color you want. Like this:
    click here
    Message was edited by: SDMacuser

  • When my husband and I first bought our iPhones, I was the only one with an Apple ID (since he never used iTunes). He used my apple id to get apps. Now he has his own ID, but my account keeps popping up on his phone. How can we change the ID on his phone?

    When my husband and I first bought our iPhones, I was the only one with an Apple ID (since he never used iTunes). He used my apple id to get apps. Now he has his own ID, but my apple ID email address keeps popping up on his phone when he tries to download an app. We do not want to have all of the same apps on our phones. How can we change the ID on his phone? I already tried going to Settings>iTunes &App Store> and changing the Apple ID to his account email and that did not solve the problem. To make things worse, I recently changed my Apple ID email address (without getting a new ID) and I do not remember my old password (and this is the address that is popping up on his phone). He does not have any music on his phone and all of the Apps that he has are free.  Any help you could offer would be great (-:

    All apps are forever tied to the Apple ID that bought them. To stop your id from popping up, you need to delete the apps on his phone, and then repurchase them under his account.

  • I can't change the volume of the background music in my project even if I put it to 0%

    I can't change the volume, I've tried to put it down with Itunes, stop and start again my computer but nothing work... PLEAAAAAASE HELP...

    Solved it, there was a problem of the same music put it twice!

  • I have both Photoshop 4 and Photoshop 6 on my computer. When I am in Bridge and want to open an image by double clicking, it automatically opens in 6. I see, when I go to "open with" 6 is listed as "default" How can I change the "double click" defult to o

    I have both Photoshop 4 and Photoshop 6 on my computer. When I am in Bridge and want to open an image by double clicking, it automatically opens in 6. I see, when I go to "open with" 6 is listed as "default" How can I change the default to open an image with a double click in 4?

    You can associate files from the Bridge level and the Desktop level.
    In Bridge CS4, go to Preferences > File Type Associations and change it to Photoshop CS4 for the file types you want.
    If you want to open files from the Windows Desktop in CS4, these are the instructions:
    Do this from the Windows Desktop:
    If you want your image file to open in Photoshop and it doesn't, right click on it and choose
    Open with > Choose default program… select Photoshop CS4 or CS6 and checkmark "always use the selected program to open this type of file".

  • How can I change the password in the iBook donated to our nonprofit.  No password was given with the iBook?  We need to put in printer and other software.  Help, we can use the laptop without changing the password.

      How can we change the password in the iBook donated to our nonprofit?  No password was given with the iBook and every time we try to install items, the password window pops up.  We need to put in printer and other software.  Help! We can use the laptop without changing the password.

    If you did not get an OS X install-restore DVD with the computer you may need
    to buy one from somewhere, and you may be lucky to get a retail OS X 10.5.x
    version. The original grey-label install set of software and OS X it shipped with
    likely would be an older system than Leopard 10.5. Last versions of G4 Mac, &
    G5, shipped with a Tiger 10.4 system; so did early Intel-based Mac. Grey discs
    which accompanied other computer build models generally do not interchange.
    The last OS X version a PowerPC architecture can use, if supported, is 10.5.8.
    A PPC processor at 867MHz & faster should be able to run OS X 10.5 Leopard.
    {With the correct disc installer, you can use it to change a password and other
    things including re-install, and perform disk utility functions, etc.}
    There is a chance you may be able to get a white-label Replacement 10.4 DVD
    or Replacement 10.5 DVD from AppleCare or the online Apple Store (800myapple)
    from a Mac OS X system specialist; these have been available yet hard to get
    as not all persons involved with them seem to know if they still exist until someone
    is asking. These aren't retail stock, are special discs for computers who could use
    a system later than original old discs; these are complete install discs not for one
    specific series of Mac. Generally they'd work in supported PowerPC G4/G5; but
    do not replace specialized original install DVD, such as an early Intel mac requires.
    You'd need to have a serial number of the computer, and a method of payment
    when seeking some replacement system media from Applecare or Apple sales
    and these discs are not available in a retail store. The original Retail discs are
    labeled differently and shipped in a retail box with a big X on the front. Other
    sources for retail 10.4 Tiger or 10.5 Leopard may be online via amazon sellers
    or computer resellers who handle repaired Macs. Avoid mystery grey label ones
    that were intended to be sold and kept with their original computer kits.
    Good luck!

  • Can you change the legth of time (or number of rings) it takes for on iphone 4 to time out making an outgonig call?

    Can you change the legth of time (or number of rings) it takes for on iphone 4 to time out making an outgonig call?
    Mostly it's to call in for radio contests. The Iphone is really good at making a quick call, but it seems to timeout after 15-20 rings. I realise this is a small thing, but free tickets is free tickets.
    Most commenst I see is abotu incoling calls, not outging.
    Thanks.

    No. You can't do this with any phone.

  • I have two iphone 4's with the same name on one computer.  Can I change the name of one so that I can sync each phone separately

    I have two iphone 4's with the same name on one computer.  Can I change the name of one so that I can sync contacts separately?

    How to rename your device in iTunes

Maybe you are looking for