CardLayout : problem on previous card

I have a frame that is composed of several panels. One of those is a DisplayPanel for displaying drawings. I use CardLayout to display the drawings. Therefore, the uses can click on the next/previous button to look at the next/previous card of drawing that is shown in the displayPanel. I test the "next" button, and it works okay.
However, when I click on the "previous button", it DOES NOT show the exact drawings that I have before navigating to the next card.
Does anyone have any clue on why this will happen and how can I fix that?
Here's the skeleton of my coding:
public class drawMap extends JPanel
     // variable declaration
     public drawMap(Vector mapData, int index)
     public Dimension getPreferredSize()
          return new Dimension(width, height);
     public void paintComponent(Graphics g)
          // loop throught the mapData vector starting from the
          //       given index that is got from the constructor
          // draw two rows
public class DisplayPanel extends JPanel implements ActionListener
     private JButton previousButton, nextButton;
     private JPanel allMaps = new JPanel(new CardLayout());
     DisplayPanel()
          add(mapPanel);
          add(buttonPanel);
     private JPanel mapPanel()
          int i=0, cardIndex=0;
          while (i < mapData.size())
               DrawMap map = new DrawMap(mapData, i)
               allMaps.add(map, String.valueOf(cardIndex));
               i = findNextIndex(); // find the next index to start for the mapData
               cardIndex++;
     private JPanel buttonPanel()
          JPanel p = new JPanel();
          previousButton = new JButton("Previous");
          previousButton.addActionListener(this);
          nextButton = new JButton("Next");
          nextButton.addActionListener(this);
          p.add(previousButton);
          p.add(nextButton);
          return p;
     private int findNextIndex()
          // find the next index to start
     public void actionPerformed(ActionEvent event)
          Object source = event.getSource();
          CardLayout cards = (CardLayout) (allMaps.getLayout());
          if (source == previousButton)
               cards.previous(allMaps);
          else if (source == nextButton)
               cards.next(allMaps);
}

Sorry for the long code. I minimize it as much as I can.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
public class MapFrame extends JPanel
    private SelectionList selection;
    private DisplayPanel display;
    public static void main(String[] args)
        javax.swing.SwingUtilities.invokeLater(new Runnable()
            public void run()
                createAndShowGUI();
    private static void createAndShowGUI()
        JFrame frame = new JFrame("Drawing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MapFrame());
        frame.pack();
        frame.setVisible(true);
        frame.setSize(500,500);
        frame.setLocationRelativeTo(null);
    public void setSelection(int c)
         display.setChoice(c);
    public MapFrame ()
        setLayout(new BorderLayout(5, 5));
        setPreferredSize(new Dimension(200, 200));
        add(display = new DisplayPanel(), BorderLayout.CENTER);
        add(selection = new SelectionList(this), BorderLayout.WEST);     
class SelectionList extends JPanel implements ActionListener
     private MapFrame parent;
     private JRadioButton circleRadio, rectRadio;
     private static final int CIRCLE = 1;
     private static final int RECT = 2;
     public SelectionList(MapFrame theParent)
          this.parent = theParent;
          add(radioButton());
     public JPanel radioButton()
          JPanel p = new JPanel(new GridLayout(2,1));     
          circleRadio = new JRadioButton("Circle");
          rectRadio = new JRadioButton("Rect");
          circleRadio.addActionListener(this);
          rectRadio.addActionListener(this);
          ButtonGroup group = new ButtonGroup();
          group.add(circleRadio);
          group.add(rectRadio);
          p.add(circleRadio);
          p.add(rectRadio);
          return p;
     public void actionPerformed(ActionEvent event)
          Object source = event.getSource();
          if (source == circleRadio)
               parent.setSelection(CIRCLE);
          else if (source == rectRadio)
               parent.setSelection(RECT);
class DisplayPanel extends JPanel implements ActionListener
     private static final int CIRCLE = 1;
     private static final int RECT = 2;
    private JButton previousButton, nextButton;
     private int choice = 0;
     private JPanel allMaps = new JPanel(new CardLayout());
     int [] list = {200, 100, 150, 100, 80, 125, 240};
     public DisplayPanel()
          GridBagConstraints gbc = new GridBagConstraints();
          gbc.anchor = GridBagConstraints.CENTER;
          gbc.insets = new Insets (5, 5, 5, 5);
          gbc.fill = GridBagConstraints.NONE;
          gbc.gridx = 0; gbc.gridy = 0; add(mapPanel(), gbc);
          gbc.gridy = 1; add(buttonPanel(), gbc);
     public void setChoice(int i)
          if (i == CIRCLE)
               choice = CIRCLE;
          else
               choice = RECT;
          mapPanel();
     private JPanel mapPanel()
          allMaps.removeAll();
          allMaps.validate();
          int i = 0;
          int cardIndex = 0;
          if (choice != 0)
               while (i < list.length)
                    DrawMap map = new DrawMap(choice, i, list);
                    allMaps.add(map, String.valueOf(cardIndex));
                    int temp = findNextStart(map, i);
                    i = temp;                         
                    cardIndex++;
               allMaps.validate();                    
          else
               DrawMap map = new DrawMap(choice, i, null);
               allMaps.add(map, String.valueOf(0));
               allMaps.validate();
          return allMaps;
     public int findNextStart(DrawMap map, int i)
          int x = 0;
          int index = i;
          while (x <= 1)
               int curXPosition = 0;
               int nextLength = 0;
               while (curXPosition + nextLength <= 400 && index < list.length)
                    int length = list[index];          
                    curXPosition += length;
                    index++;
                    if (index < list.length)
                         nextLength = list[index];
               x++;
          return index;
     private JPanel buttonPanel()
          JPanel p = new JPanel();
          previousButton = new JButton("Previous");     
          previousButton.addActionListener(this);
          nextButton = new JButton("Next");     
          nextButton.addActionListener(this);
          p.add(previousButton);
          p.add(nextButton);
          return p;
     public void actionPerformed(ActionEvent event)
          Object source = event.getSource();
          CardLayout cards = (CardLayout) (allMaps.getLayout());
          if (source == previousButton)
               cards.previous(allMaps);
          else if (source == nextButton)
               cards.next(allMaps);
class DrawMap extends JPanel
     private static final int D_WIDTH = 400;
     private static final int D_HEIGHT = 400;
     private static final int CIRCLE = 1;
     private static final int RECT = 2;
     int width, height;
     int choice;
     int [] list;
     int index;
     public DrawMap(int c, int counter, int[] l)
          width = D_WIDTH;
          height = D_HEIGHT;
          choice = c;
          index = counter;
          list = l;
     public Dimension getPreferredSize()
          return new Dimension(width, height);
     public void paintComponent(Graphics g)
          super.paintComponent(g);
          Graphics2D g2d = (Graphics2D) g;
          if (list != null)
               int x = 0;
               while (x <= 1)
                    int gridYLine = (height/2) * x;
                    int curXPosition = 0;
                    int nextLength = 0;
                    while (curXPosition + nextLength <= width && index < list.length)
                         int length = list[index];
                         if (choice == CIRCLE)
                              g2d.drawOval(curXPosition, gridYLine, length, length);
                         else
                              g2d.drawRect(curXPosition, gridYLine,length, length);
                         curXPosition += length;
                         index++;
                         if (index < list.length)
                              nextLength = list[index];
                    x++;
}

Similar Messages

  • My app store wont let me download apps, says the card is expired and theres a problem with previous purchase can someone help me pls?

    My app store wont let me download apps, asks me to update my payment details then says theres a problem with previous purchase and card is expired which is untrue someone help me pls

    This is a User to User Forum...
    See Here for
    Mac Apps Store Customer Service
    http://www.apple.com/support/mac/app-store/contact.html?form=account
    iTunes Customer Service Contact
    http://www.apple.com/support/itunes/contact.html

  • Download or upgrade current and free apps says there's a billing problem with previous purchase previous purchase what can I do to fix it

    Every time I try to download a free app or even upgrade any of my apps for free it tells me to put my Apple ID I do that then it say there a billing problem with previous purchases. So I click continue and put in my debit card information correctly but still won't work it always declines it and says he's different payment method. what can I do it's been like that for 3 months that's the only card I have.

    Hi ..
    I replied to you here >  Download or upgrade current and free apps says there's a billing problem with previous purchase previous purchase what can I do to fix it

  • Problem with updating card information

    I've recently gotten a new debit card and am having problems updating my billing information.  My CC account was originally created with my previous debit card.  My new debit card is of the exact same type, a VISA, but, of course with a new number.  However, when I try to update my card information it tells me that my new card is not of the accepted type.  This doesn't make any sense to me because the card, as I stated, is a VISA and exactly the same as my previous card with which I purchased my account.  Is anyone else having this problem or can anybody help me?  Thanks.

    It is happening to me too.
    The only difference that mine is Mastercard. I get the Card not of accepted type message.
    Chatting with the Indian support guy was unsuccesful, after 30 minutes, he/she was able to decide, that "your account is active"... Congratulations. When I asked what next,, I was promised that I will be called by another colleague the next business day. It was 4 days ago... Today I called the local support number, and it turns out it's just a distributor without the ability to help in this topic. I do not want to call an international support number, to spend n+10 minutes on the phone with an inferior helpdesk person to find out again, that "oooh yes, my account is alive".
    @ameredith - could you get it sorted out somehow?

  • Problem with credit card verification with firefox 4 (works with safari!)

    I recently upgraded to Firefox 4 and tried to book train tickets online. I have done this many times before with earlier Firefox versions. Now however, after being redirected to the card verification page and submitting my security details, instead of confirming my booking Virgin trains asks me to log on again! I thought it was a problem with the website but I subsequently booked the tickets using Safari so I guess that means there is a problem with Firefox 4. Can I go back to the previous version?

    I, also, have previously made credit card purchases with Firefox version 3 without any problems.
    I only encountered this problem with credit card verification after downloading Firefox 4. I was however able to book tickets successfully, the same day, using Internet Explorer and the card verification went through as normal. I am confident that the problem was due to problems with the new version of Firefox.

  • My iPhone 4S not compatible with 2008 Q7 Audi MMI.  Now only phone numbers come up on screen, no name.  Names appeared on the phone screen but not MMI screen. Cannot dial by contact info while driving anymore.  Never had this problem with previous iPhones

    My iPhone 4S not compatible with 2008 Q7 Audi MMI.  Now only phone numbers come up on screen, no name.  When someone calls, only the number appears on the MMI screen, not their name or whether they called from their office/home etc..   Same with missed calls, dialed numbers etc.. Names appeared on the screen of the phone,  but not on MMI screen. Cannot dial by searching  contact and name info while driving anymore.  Never had this problem with previous iPhones.  Is this an Apple issue or Audi issue?  Anyone with this problem? Help!

    NIGHTMARE Finally Ends, after nearly two weeks.
    After trying for over a week trying to get my replacement iPhone 4S to activate, I ended up driving 110+ miles to an Apple Store to get a second replacement, which had been specially shipped there for me.  Popped in the SIM card, went through the setup and I finally have an iPhone 4S that works, at least for the time being.
    Advice to others who find themselves in this situation:
         1)     If you get these messages (see original post), the phone is bad.  Demand a replacement.
         2)     If the AppleCare tech advises that the Apple Agreement Administration team is investigating, you'll be waiting for a week or more for them to complete it.  Demand a replacement immediately, don't let them put you off indefinitely.
    After the initial phone call documented in my original post, I was in daily contact, phone & e-mail, with the AppleCare tech trying to figure out the problem, and we tried everything, from forced restore's to switching SIM cards, conferencing w/ AT&T, etc.  It seems that this was a case of first impression to Apple, but if it wasn't, then the problem is not well documented or known by those who should know, and for that, the blame should be on Apple, not the AppleCare tech who worked tirelessly trying to figure out a solution--I'd send him a case of beer if I knew where to send it.

  • CardLayout with JScrollPane: Make card changes show top of card

    I'm sure that I'm not the first one to ask this, but I could not find the answer anywhere else on this forum.
    I have a CardLayout that shows two cards.
    Each card has a JScrollPane on it, so that you can scroll the contents.
    In my program, I switch the views of each card back and forth, the problem is:
    if I show Card A, then scroll to the bottom of Card A
    then switch to Card B,
    then switch back to Card A,
    I see the bottom of Card A.
    I want to Card A from the top. I am using jdk 1.3.1
    Any ideas?

    During the handler (lisener) calls that do the switching, make a call like the followingmyScrollPane.getViewport().
                   setViewPosition(new Point(0,0))

  • How do i change my bank account information on my appleid if my previous card number has changed

    how do i change my bank account information on my appleid if my previous card number has changed

    Tap Settings > iTunes & App Stores then tap Apple ID > View Apple iD > Payment Information

  • HT201359 i have a problems while purchasing or download a free item in apps store or itunes, it said that you have a problems with previous purchase, it also said that my payment method was decline.,..

    i have a problems while purchasing or download a free item in apps store or itunes, it said that you have a problems with previous purchase, it also said that my payment method was decline.,..

    Hi shldr2thewheel,
         it has been a while since we have last spoke, I would like to let you know, I am still working on getting used to the switch from windows to a Mac/Apple system. I do have a new question for you, I did purchase In Design CS5.5 through journeyed.com through Cuyahoga Community College of which I attend as a student, is there a way to purchase an online book through iTunes to learn that as well? Also, you know me, the struggling student, I would also, when and if the book can be purchased through the iTunes, would need to know if you do know of a much easier book for struggling students like myself and at a reasonable price as well for the In Design CS5.5 program. Our campus bookstore had closed early, and, so did the colleges library and our local library here where I do live, so, I cannot go to either place to purchase a book or to take out a book, plus cash funds are low at this moment as well but, I do have money left on the iTunes account to use, if it can be used. So, can it be used, the iTunes money, towards finding a low priced online book? I am in great need of assistance as I have a project due for my one course for this Tuesday, September 4, 2012.
    Sincerely in need of help once again,
    Kim

  • I can't send texts to some contacts in my iphone 4s. This is a recent problem, as previously all texts would send. The red exclamation mark appears and 'not 'delivered' shows on screen.

    First time I've used this discussion forum, so may be posting problem twice! I can't send texts to some contacts in my iphone 4s. This is a recent problem, as previously I could send texts whenever I wanted. The exclamation mark and "not delivered' shows on screen when I ry and text certain people. I know for a fact that my number is not blocked by the receipients?

    I've just realised, further to my earlier question - that the people I am trying to text do not have Iphones? Could this make a difference? (Although I have text them in the past)

  • Hi there, I moved to a new country (Luxembourg ), my previous card is not working anymore, I am trying to change country and region but it looks like the option is not available, could you support on the issue please ? Thx ahead, Corneliu

    Hi there, I moved to a new country (Luxembourg ), my previous card is not working anymore, I am trying to change country and region but it looks like the option is not available, could you support on the issue please ? Thx ahead, Corneliu

    CHANGING APPLE ID/EDIT ACCOUNT INFORMATION/CHANGE ITUNES COUNTRY
    Tap Settings / iTunes & App Stores, then tap the Apple ID signed in. Sign out of the current Apple ID account and then sign in with another account or create a new Apple ID http://support.apple.com/kb/HT2731?viewlocale=en_US
    Go to settings/facetime and tap the ID there and log out and log in with new ID.
    Go to settings/messages and turn off imessages wait 30 seconds and turn it back on, go to “receive messages  at” tap on the ID there, sign out and sign in with new ID.
    Go to settings/icloud and delete the account and when prompted select “keep information on your device” then turn it back on with the new ID.
    To edit account information tap Settings / iTunes & App Stores / Apple ID: / View Apple ID
    To change your iTunes Store country, sign in to the account for the iTunes Store region you would like to use, tap Settings/iTunes & App Store/Apple ID/View Apple ID/Country/Region
    Read this article for information http://support.apple.com/kb/HT1311

  • Problem with RSC card on sun fire v490

    Hi all,
    I have a little problem.
    I got few v490 that were already used.
    When I connect to the management port of the RSC card I get the prompt of the RSC password, somthing i don't have.
    The OS doesn't get loaded and I can't do anything. ( if I had access to the OS I would have reseted the password)
    So now, I got left with the only option i thought of.
    1. Disconnect the RSC card,
    2. This will force the output of the consol to go to the serial port(tty).
    3. Jumpstart the machine (beacuse I don't even have the password for the machine)
    4. connect the RSC card, and reset the password.
    There is someone here that encountered this problem??
    Maybe there is a jumper that can reset the RSC password. i don't know... every response will be great!
    Thanks!!!

    Hi,How to set my link up in solaris 10 ?
    I dont know want happend to my machine solaris v440 it suddenly disconnected from n/w and finally i came to know that is a problem with NIC card..i din't find any light's glowing back side of the machine at NIC card.
    can any one help me in this pls how can i proceed furture for getting my NIC back?
    and i have excuted few commands
    #ndd -set /dev/ce instance 0
    #ndd -set /dev/ce adv_1000fdx_cap 1
    #ndd -set /dev/ce adv_autoneg_cap 0
    I have got dladm show-dev is
    ce0 link: unknown speed: 1000 Mbps duplex: full
    ce1 link: unknown speed: 0 Mbps duplex: unknown
    I dont understand that why my link is showing still unknown ...any help..

  • Problem with SD card reader

    I have problem with 4-in-1 card reader in my laptop.
    When I insert 64 MB microSD (with adapter of course) everything is working fine, but 1024 MB microSD isn't working. dmesg shows
    mmc0: unrecognised SCR structure version 1
    mmc0: error 4 whilst initialising SD card
    The card is allright, because in my friend's laptoptop it works fine.
    Can somebody help me?

    Hi
    I had a problem with my card reader also.
    When I run the command "groups" noticed my user wasn't in the avahi group.
    Ran :
    sudo gpasswd -a <myuser> avahi
    (substitute "<myuser>" by your user)
    Inserted the card again and.. voila, it worked!
    Greets
    Nuno lopes

  • Yoga 11s Problem with SD Card reader

    Hi.
    Just bought a Yoga s11 8/256gb with windows 8 64bit.
    When i put in the SDHC card (Is use in camera) in the SD card reader nothing happends..
    Tried to download drivers, but not sure if i got the correct one.

    Hi
    I had a problem with my card reader also.
    When I run the command "groups" noticed my user wasn't in the avahi group.
    Ran :
    sudo gpasswd -a <myuser> avahi
    (substitute "<myuser>" by your user)
    Inserted the card again and.. voila, it worked!
    Greets
    Nuno lopes

  • Has anyone got an answer to fix ios5 problem, no sim card inserted...

    Has anyone got an answer to fix ios5 problem, no sim card inserted...

    I bought a new sim card today at the t-mobile shop and they activated the card just by putting credit on, i got home put the sim in the iphone and still got the same message. I have restored and shut down I dont know how many times and updated itunes, I am wishing i had said no to updating the phone as i have no iphone to use and apple say i should go to an apple shop.

Maybe you are looking for

  • XML source content problem in 5.0.2

    Hi, I installed optional web component xml source portlet and I migrated ptxmlsp content in my 5.0.2 portal successfully on MS .NET. I have instentied my portlet with well formed xml and xsl files. Displaying page, portlet display message "Error: Dis

  • How do I make the background of a logo transparent on a slide?

    This seems to be doc'd in the Captivate 7 User Guide, in "Properties of images and rollover images": ImageTransparent Background Select the color filler icon. All occurrences of one particular color in an image can be made transparent. ...  However,

  • IPod classic will not connect in iTunes

    My iPod classic 30gb (not sure if 4th or 5th gen) will not display in iTunes. I have followed the steps on apple support and came to the conclusion that windows was confusing the my ipod with a network drive but I cannot change the drive letter, an e

  • Credit card compromised!

    my Visa was charged for a purchase thru compaq. if i have my credit card company file a complaint would you be able to trace the shipping address??

  • Problem normalizing the receiver- PARTY

    Dear all, Hi, experts! We have a FILE to FILE scenario which return this error in XI monitor: "RCVR_DETERMINATION">CX_RD_PLSRV</SAP:Code>   <SAP:P1>Problem normalizing the receiver: Normalization: Alternative party ID 'TPV_0021' does not exist (agenc