I Can't switch my CardLayout @.@

There is a card 3 but i havn't add ,so the "Enterbtn" is to trigger card 3.
So what is wrong with my code that it can't switch? I changed the cardPanel from 2 to 1 and 1 to 2 but it only appear card 2.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class HPhoneInv extends JFrame {
private int currentCard = 1;
private JPanel cardPanel;
private CardLayout cl;
public HPhoneInv() {
setTitle("Handphone Inventory System");
setSize(500, 160);
cardPanel = new JPanel();
cl = new CardLayout();
cardPanel.setLayout(cl);
JPanel jp1 = new JPanel();
jp1.setLayout(new GridLayout(1,1) );
JLabel jl1 = new JLabel("Select Option:");
jp1.add(jl1);
cardPanel.add(jp1, "1");
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,2) );
JButton AcqBtn=new JButton("Used Phone Acquisition");
JButton TranBtn=new JButton("Sale Transaction");
buttonPanel.add(AcqBtn);
buttonPanel.add(TranBtn);
getContentPane().add(jp1, BorderLayout.NORTH);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
JPanel jp2 = new JPanel();
jp2.setLayout(new GridLayout(5,2) );
JLabel lbl1 = new JLabel("Cust IC No:");
JLabel lbl2= new JLabel("Brand:");
JLabel lbl3 =new JLabel("Model:");
JLabel lbl4=new JLabel("Serial No:");
JLabel lbl5=new JLabel("Cost:");
JTextField tf1=new JTextField("");
JTextField tf2=new JTextField("");
JTextField tf3=new JTextField("");
JTextField tf4=new JTextField("");
JTextField tf5=new JTextField("");
jp2.add(lbl1);
jp2.add(tf1);
jp2.add(lbl2);
jp2.add(tf2);
jp2.add(lbl3);
jp2.add(tf3);
jp2.add(lbl4);
jp2.add(tf4);
jp2.add(lbl5);
jp2.add(tf5);
cardPanel.add(jp2, "2");
JPanel buttonPanel2 = new JPanel();
buttonPanel2.setLayout(new GridLayout(1,2) );
JButton EnterBtn=new JButton("Enter");
JButton CancelBtn=new JButton("Cancel");
buttonPanel2.add(EnterBtn);
buttonPanel2.add(CancelBtn);
getContentPane().add(jp2, BorderLayout.NORTH);
getContentPane().add(buttonPanel2, BorderLayout.SOUTH);
AcqBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (currentCard < 2) {
currentCard +=1;
cl.show(cardPanel, "" + (currentCard));
TranBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (currentCard < 2) {
currentCard += 1;
cl.show(cardPanel, "" + (currentCard));
EnterBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (currentCard > 1) {
currentCard = 1;
CancelBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (currentCard > 1) {
currentCard = 1;
cl.show(cardPanel, "" + (currentCard));
public static void main(String[] args) {
HPhoneInv cl = new HPhoneInv();
cl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cl.setVisible(true);
Message was edited by:
RockmanEXE
Message was edited by:
RockmanEXE

The order of the components, added into the cards and into the JFrame are wrong, so i just rearranged the order and i added one more JPanel.
so based on that, u code accordinglyimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class HPhoneInv extends JFrame {
    private int currentCard = 1;
    private JPanel cardPanel;
    private CardLayout cl;
    JPanel card1 = null;
    JPanel card2 = null;
    public HPhoneInv() {
        setTitle("Handphone Inventory System");
        setSize(500, 160);
        cardPanel = new JPanel(new CardLayout());
        JPanel jp1 = new JPanel();
        jp1.setLayout(new GridLayout(1,1) );
        JLabel jl1 = new JLabel("Select Option:");
        jp1.add(jl1);
        //cardPanel.add(jp1, "1");
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(1,2) );
        JButton AcqBtn=new JButton("Used Phone Acquisition");
        JButton TranBtn=new JButton("Sale Transaction");
        buttonPanel.add(AcqBtn);
        buttonPanel.add(TranBtn);
        card1 = new JPanel(new BorderLayout());
        //getContentPane().add(jp1, BorderLayout.NORTH);
        //getContentPane().add(buttonPanel, BorderLayout.SOUTH);
        card1.add(jp1, BorderLayout.NORTH);
        card1.add(buttonPanel, BorderLayout.SOUTH);
        card2 = new JPanel(new BorderLayout());
        JPanel jp2 = new JPanel();
        jp2.setLayout(new GridLayout(5,2) );
        JLabel lbl1 = new JLabel("Cust IC No:");
        JLabel lbl2= new JLabel("Brand:");
        JLabel lbl3 =new JLabel("Model:");
        JLabel lbl4=new JLabel("Serial No:");
        JLabel lbl5=new JLabel("Cost:");
        JTextField tf1=new JTextField("");
        JTextField tf2=new JTextField("");
        JTextField tf3=new JTextField("");
        JTextField tf4=new JTextField("");
        JTextField tf5=new JTextField("");
        jp2.add(lbl1);
        jp2.add(tf1);
        jp2.add(lbl2);
        jp2.add(tf2);
        jp2.add(lbl3);
        jp2.add(tf3);
        jp2.add(lbl4);
        jp2.add(tf4);
        jp2.add(lbl5);
        jp2.add(tf5);
        //cardPanel.add(jp2, "2");
        JPanel buttonPanel2 = new JPanel();
        buttonPanel2.setLayout(new GridLayout(1,2) );
        JButton EnterBtn=new JButton("Enter");
        JButton CancelBtn=new JButton("Cancel");
        buttonPanel2.add(EnterBtn);
        buttonPanel2.add(CancelBtn);
        //getContentPane().add(jp2, BorderLayout.NORTH);
        //getContentPane().add(buttonPanel2, BorderLayout.SOUTH);
        card2.add(jp2, BorderLayout.NORTH);
        card2.add(buttonPanel2, BorderLayout.SOUTH);
        cardPanel.add(card2,"two");
        cardPanel.add(card1,"one");
        this.getContentPane().add(cardPanel);
         AcqBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                    CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());
                    cardLayout.show(cardPanel,"two");
                /*if (currentCard < 2) {
                    currentCard +=1;
                    cl.show(cardPanel, "" + (currentCard));
           TranBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                    CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());
                    cardLayout.show(cardPanel,"two");
                /*if (currentCard < 2) {
                    currentCard += 1;
                  cl.show(cardPanel, "" + (currentCard));
            EnterBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                    //System.out.println("Enter Button got clicked");
                    CardLayout cardLayout = (CardLayout)(cardPanel.getLayout());
                    cardLayout.show(cardPanel,"one");
         CancelBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                    System.exit(0);
                if (currentCard > 1) {
                    currentCard = 1;
                  cl.show(cardPanel, "" + (currentCard));
    public static void main(String[] args) {
        HPhoneInv cl = new HPhoneInv();
        cl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        cl.setVisible(true);
}

Similar Messages

  • My fiance logged onto my iphone with his apple ID and now I can't switch it back to my username. How can I change it back to mine? ( but when I go to setting,icloud my un/pw are there)

    My fiance logged into my iphone with his apple ID and now I can't switch it back to my username. When I go to buy an app his username is in an editable format to beable to change it back to mine. How can I change it back to mine? (when I go to setting,icloud my un/pw are there) Can someone please help? Thanks!

    Had you looked in the User Guide, you would have found this:  Settings>Store.  Tap on AppleID to change.

  • HELP NEEDED!! I bought a brand new mac air 11 inch a month ago, and for three days now I can't switch it on.when I do, i can hear the machine is on, but nothing else happens. (yes it is charged). please help

    HELP NEEDED!! I bought a brand new mac air 11 inch a month ago, and for three days now I can't switch it on.when I do, i can hear the machine is on, but nothing else happens. (yes it is charged). please help.
    I bought it in South Africa and I am currently in Israel.

    thank you for the response.its not working, tried that. i can switch the machine on and off, can hear the machine when i hold it to my ear. but nothing works, not the screen, not the sound, nothing.

  • How can I switch from auto_login wallet to password-protected encryption wallet in 12c  ?

    How can I switch from auto_login wallet to password-protected encryption wallet in 12c
    --Now the autologin wallet is in effect
    SQL> select * from v$encryption_wallet
      2  ;
    WRL_TYPE
    WRL_PARAMETER
    STATUS       WALLET_TYPE    WALLET_OR FULLY_BAC
        CON_ID
    FILE
    /acfs3/wallet
    OPEN       AUTOLOGIN    SINGLE    NO
      0
    --I need to export the keys and it informs me to use password-based keystore
    SQL> ADMINISTER KEY MANAGEMENT export KEYS with secret tde_1234 to '/home/oracle/dumpdir/orapdba.wallet' IDENTIFIED BY "tde_1234";
    ADMINISTER KEY MANAGEMENT export KEYS with secret tde_1234 to '/home/oracle/dumpdir/orapdba.wallet' IDENTIFIED BY "tde_1234"
    ERROR at line 1:
    ORA-28417: password-based keystore is not open
    --So I try to close the autologin keystore and open the password-based keystore, but the autologin keystore cannot be closed
    SQL>  administer key management set keystore close;
    administer key management set keystore close
    ERROR at line 1:
    ORA-28365: wallet is not open
    SQL> administer key management set keystore open identified by "tde_1234";
    administer key management set keystore open identified by "tde_1234"
    ERROR at line 1:
    ORA-28354: Encryption wallet, auto login wallet, or HSM is already open
    So My question is
    How to switch from auto_login keystore to password-protected keystore ?

    Remove the cwallet.sso file and check the wallet status in v$encryption_wallet.
    If it is not opened, try to open it with administer key statement.
    Check the status again.

  • How can I switch money to another iTunes account ?

    I Dont know my security questions and the rescue email . So can I switch the money over to a different account ?

    You can't. And you don't want to do that anyway. Setting up a new iTunes account will not help you when you want to update apps purchased under the one you can't remember the Security Questions for. You will need the password for that account to update any apps purchased under it.
    Contact iTunes Support to get your Security Questions reset:
    ACCOUNT SECURITY CONTACT NUMBERS
    Cheers,
    GB

  • How can I switch my apple I'd email address on my ipad to my gmail account that was associated to another device I own?

    How can I switch my apple I'd email address on my ipad to my gmail account that was associated to another device I own?
    I lost the other device so I don't even have it, and I want to terminate the email account I am currently using.

    settings --> Store --> Apple ID.

  • HT201303 I own two apple ids with 2 different devices how can I switch IDs on a device?

    I have an IPhone 5 and just got an IPad. I set up a new Apple ID for IPad but can not download my apps from IPhone how can I switch on my IPad to apps I had purchased on my IPhone. I want to play my games on larger screen.

    There is no "adding" a device.  Simply plug the iDevice into the computer.  iTunes should automatically detect the device when it is connected.
    iTunes can sync/manage as many iDevices as you want... there is no 1 device limit.

  • HT201320 How can I switch from one email user to another?

    How can I switch from one email account to another?

    You have to select between the two accounts in the mail app.
    Say for instance that you are reading an email in your XYZ email account. Tap the button in the upper left corner of the mail app to back out all the way to where you can see all of the email accounts.... Tap InBox, then tap XYZ email Account and that will take you back to the main MailBoxes window.
    Is that what you want to know? There is no way to simply "toggle" between the two accounts.

  • Sometimes when I play songs in Itunes by double clicking on them, Itunes will place the song as the first one on the album.  It will chnage the order of the songs on the album, and I can not switch them back to the correct order.

    Sometimes when I play songs in Itunes by double clicking on them, Itunes will place the song as the first one on the album.  It will chnage the order of the songs on the album, and I can not switch them back to the correct order.  This onloy seems to happen when I double-click on the song to play it in itunes.  If I just hit play, this doesnt happen.  As a result, I have several albums now in which the songs are in the wrong order.  Its very frustrating, as this error then transfers over to my ipod every time I sync it.  When I choose the info. for the songs, it has them correctly listed (i.e., it lists the songs as being #1 of 19 on the CD, for example).  But then the song will have placed by Itunes as #5 of 19 for whatever reason.  Itunes does not do this every time, but does it with enough frequency to be maddening.  Any thoughts?

    The problem of tracks becoming de-linked between iTunes and the music files in your iTunes music folder happens for different reasons - this seems to come up fairly commonly in this forum.
    The solution can be to locate each song in the iTunes library, as you mentioned - or, but wait, before I get to that...
    trouble finding the original track in your iTunes music folder? maybe look for it under compilations, or if not using the 'group compilations preference' then look in the folder under the songs artist name, but what song artist name iTunes uses depends on what you have in the metedata tag spot for album artist or song artist. Any varyation in artist name spelling, in the menu item 'get info' metadata for any selected individual track will cause iTunes to create that as a separate artist folder in the library, even names like 'various' or any difference at all (even the word 'the' can change where in your iTunes music folder a track gets placed by iTunes). You can try to use the finder function of find file (finder munu item outside of iTunes) to locate hard to find items.
    Back to how to re-link any de-linked tracks .
    There may be scripts that can help re-link de-linked music files - or, at least provide you a list of such files, Scripts are easy to install and use...
    at Dougs Scripts, there is one called iTunes Track CPR that might work
    http://dougscripts.com/itunes/scripts/ss.php?sp=itunestrackcpr
    or, if you just want a list of de-linked tracks, go to
    http://dougscripts.com/itunes/
    and find the script called List MIA's, this will create a text file listing all de-linked tracks
    if you review the thread at
    https://discussions.apple.com/thread/3633708
    also the thread at
    https://discussions.apple.com/message/17513078#17513078
    you may find more insight into dealing with this kind of issue there, although some of that thread may not apply to your case, aspects of it might help.
    Good luck.

  • HT4818 hey, I want to install windows on my mac, I have mac osx lion and I'm soon going to get mountain lion. If I use Boot camp to install windows do I need a windows disc, will i lose all my data, etc. If so how to I save them. Can I switch back to osx

    hey, I want to install windows on my mac, I have mac osx lion and I'm soon going to get mountain lion. If I use Boot camp to install windows do I need a windows disc, will i lose all my data, etc. If so how to I save them. Can I switch back to osx after I install windows. ( can I switch between Windows and OS X as many times as I want.) thanks for answering.
    Sebastian

    hey, I want to install windows on my mac, I have mac osx lion and I'm soon going to get mountain lion. If I use Boot camp to install windows do I need a windows disc, will i lose all my data, etc. If so how to I save them. Can I switch back to osx after I install windows. ( can I switch between Windows and OS X as many times as I want.) thanks for answering.
    Sebastian

  • How can I switch between multiple windows of the same application (e.g. Safari) over several desktops ?

    Hi All,
    I have one application, for example safari, open and running with multiple windows (with or without tabs) spread over several desktops.
    How can I switch between the windows only via keyboard? CMD+> and CMD+< let me only swicht between windows open on the one desktop I am currently looking at.
    thanks for your replies,
    equi

    Barney,
    many thanks for your efforts and your time (preparing and posting the screenshot, answering to this question,...).
    Unfortunately, moving the focus to the next window only works with windows on the same desktop.
    btw, using a german keyboard layout and german language settings the shortcut is "cmd+<".
    I can switch with this shortcut between different windows of my Safari which reside on the same desktop, but I cannot swith between different safari windows distributed over several desktops.
    Thanks,
    equi    

  • I rented an HD movie in iTunes by mistake. Can I switch the rental to SD version before starting to watch it? Trying to make room on iPad.

    I rented an HD movie in iTunes by mistake. Can I switch the rental to SD version before starting to watch it? Trying to make room on iPad for more rentals to take with me on trip.

    You can get the SD or 720p version by:
    Open iTunes 11
    Click iTunes in menu bar > select Preferences...
    Click on the Store tab
    Change When downloading High Definition videos, prefer dropdown to 720p > click OK
    Click on the iTunes Store button
    Click Purchased link
    Click Movies tab
    You should now see a download icon for the movies you already have 1080p version of.
    Click on this download icon to download the 720p version.
    This will put a 720p version in the same folder on your hard drive as the 1080p version.  If you have iTunes setup to play 1080p when available, it will play the 1080p version.  When you connect your iPad 1, it will sync the 720p version.
    Don't forget to change your preference back to 1080p so you can continue to get the higher quality version.

  • Had my computer serviced recently and had to reinstall itunes. Now I two accounts. How can I switch to my original account that has all the music I imported into itunes and get rid of the new account?

    Had my computer serviced recently and had to reinstall itunes. Now its saying I have two accounts. How can I switch to my original account where all my music that I imported is and get rid of the new one that only shows my purchased music?

    Had my computer serviced recently and had to reinstall itunes. Now its saying I have two accounts. How can I switch to my original account where all my music that I imported is and get rid of the new one that only shows my purchased music?

  • I want to order a second copy of an iPhoto book. Thought created in the smaller format only the larger format is showing. How can I switch an existing iPhoto book back to the smaller format?

    I want to order a second copy of an existing iPhoto book. Though created in the smaller format now only the larger format is showing. How can I switch an existing iPhoto book back to the smaller format?

    To change a book size duplicate it (select the book in the source pane and press command and D) since text flow and picture  placements can change due to the size differences - then click on change themes, select the same theme and the new size
    check it carefully
    Before ordering your book preview it using this method - http://support.apple.com/kb/HT1040 - and save the resulting PDF for reference - the delivered book will match it.
    LN

  • I tried to update the App that I purchased but the message told me that my Apple account is not valid for use outside of US and I must switch back to US store to able to do it. How can I switch the account from foreign countries back to US?

    I tried to update the App that I purchased but the message told me that my Apple account is not valid for use outside of US and I must switch back to US store to able to do it. How can I switch the account from foreign countries back to US?

    On your phone (from http://support.apple.com/kb/ht1311):
    Change your iTunes Store country
    Sign in to the account for the iTunes Store region you'd like to use. Tap Settings > iTunes & App Stores > Apple ID: > View Apple ID > Country/Region.
    Follow the onscreen process to change your region, agree to the terms and conditions for the region if necessary, and then change your billing information.

Maybe you are looking for

  • Does home sharing on Apple TV require I keep my MacBook Pro 'live'

    Got my new Apple TV. Setup was fairly easy. Homesharing works fine. Except -- even if I have home sharing turned on, and my MacBook Pro on and iTunes on (open), if I close my laptop/it goes to sleep (and it's in another room), my Apple TV no longer c

  • Shared services installation.

    through configuration utility - i am unable to configure shared services (configure database and deploy to App Server) . Given username & Password ( hypuser and password ) for SID (hypuser) on Database configuration details popup. got the below error

  • Bulk Account Merge

    Hello Experts, I have a situation where I need to merge good number of accounts: some 500 accounts are needed to be merged to different 500 accounts. I need to know if any report exists in CRM 7.0 to execute this or any upload possible for it. Also i

  • What are the iTunes Podcast Categories?

    Hi Can you please send me a link to an up to date list of the podcast categories and subcategories of the iTunes store I can't find it anywhere in the apple help section thanks

  • Is it possible to create Flash

    Hi I am new to AIR ,Is it possible to create Flash Video Encoder type application using AIR ?