// Set up the quiz window
 Quiz() {
   initializeData();
   setTitle("FOSS Quiz App");
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setSize(440, 400);
   setLocation(300, 100);
   setResizable(true);
   Container cont = getContentPane();
   cont.setLayout(null);
   cont.setBackground(Color.WHITE);
   bg = new ButtonGroup();
   choice1 = new JRadioButton("Choice1", true);
   choice2 = new JRadioButton("Choice2", false);
   choice3 = new JRadioButton("Choice3", false);
   choice4 = new JRadioButton("Choice4", false);
   bg.add(choice1);
   bg.add(choice2);
   bg.add(choice3);
   bg.add(choice4);
   lblmess = new JLabel("Choose a correct anwswer");
   lblmess.setForeground(Color.BLACK);
   lblmess.setFont(new Font("Sans_Serif", Font.BOLD, 15));
   btnext = new JButton("Next");
   btnext.setForeground(Color.WHITE);
   btnext.setFont(new Font("Sans_Serif", Font.BOLD, 17));
   btnext.setBackground(Color.DARK_GRAY);
   btnext.addActionListener(this);
   panel = new JPanel();
   panel.setBackground(Color.WHITE);
   panel.setLocation(10, 60);
   panel.setSize(400, 300);
   panel.setLayout(new GridLayout(0, 1));
   title = new JPanel();
   title.setBackground(Color.WHITE);
   title.setLocation(10, 10);
   title.setSize(1000, 50);
   title.setLayout(new GridLayout(1, 0));
   title.add(lblmess);
   panel.add(choice1);
   panel.add(choice2);
   panel.add(choice3);
   panel.add(choice4);
   panel.add(btnext);
   cont.add(title);
   cont.add(panel);
   setVisible(true);
   quizAnswerID = 0;
   readQuestionAnswer(quizAnswerID);
 }
  /**
   * setupNoLandPermPanel.
   *
   * @param p a {@link javax.swing.JPanel} object.
   * @param list a {@link java.util.ArrayList} object.
   * @param stack a boolean.
   */
  private static void setupNoLandPermPanel(JPanel p, ArrayList<Card> list, boolean stack) {

    int maxY = 0;
    int maxX = 0;

    Card c;

    if (stack) {
      // add all Cards in list to the GUI, add arrows to Local Enchantments

      ArrayList<Card> planeswalkers = getPlaneswalkers(list);
      ArrayList<Card> equippedEnchantedCreatures =
          getEquippedEnchantedCreatures(
              list); // this will also fetch the equipment and/or enchantment
      ArrayList<Card> nonTokenCreatures = getNonTokenCreatures(list);
      ArrayList<Card> tokenCreatures = getTokenCreatures(list);

      // sort tokenCreatures by name (TODO: fix the warning message somehow)
      Collections.sort(
          tokenCreatures,
          new Comparator<Card>() {
            public int compare(Card c1, Card c2) {
              return c1.getName().compareTo(c2.getName());
            }
          });

      ArrayList<Card> artifacts = getNonCreatureArtifacts(list);
      ArrayList<Card> enchantments = getGlobalEnchantments(list);
      // ArrayList<Card> nonBasics = getNonBasics(list);

      list = new ArrayList<Card>();
      list.addAll(planeswalkers);
      list.addAll(equippedEnchantedCreatures);
      list.addAll(nonTokenCreatures);
      list.addAll(tokenCreatures);
      list.addAll(artifacts);
      list.addAll(enchantments);

      int atInStack = 0;

      int marginX = 5;
      int marginY = 5;

      int x = marginX;

      int cardOffset = Constant.Runtime.stackOffset[0];

      String color = "";
      ArrayList<JPanel> cards = new ArrayList<JPanel>();

      ArrayList<CardPanel> connectedCards = new ArrayList<CardPanel>();

      boolean nextEquippedEnchanted = false;
      int nextXIfNotStacked = 0;
      Card prevCard = null;
      for (int i = 0; i < list.size(); i++) {
        JPanel addPanel;
        c = list.get(i);
        addPanel = new CardPanel(c);

        boolean startANewStack = false;

        if (!isStackable(c)) {
          startANewStack = true;
        } else {
          String newColor = c.getName(); // CardUtil.getColor(c);

          if (!newColor.equals(color)) {
            startANewStack = true;
            color = newColor;
          }
        }

        if (i == 0) {
          startANewStack = false;
        }

        if (!startANewStack && atInStack == Constant.Runtime.stackSize[0]) {
          startANewStack = true;
        }

        if ((c.isEquipment() || c.isAura())
            && (c.isEquipping() || c.isEnchanting())
            && !nextEquippedEnchanted) startANewStack = false;
        else if ((c.isEquipment() || c.isAura()) && (c.isEquipping() || c.isEnchanting())) {
          startANewStack = true;
          nextEquippedEnchanted = false;
        }

        if (c.isCreature() && (c.isEquipped() || c.isEnchanted())) {
          startANewStack = false;
          nextEquippedEnchanted = true;
        }
        // very hacky, but this is to ensure equipment stacking occurs correctly when a token is
        // equipped/enchanted, and there are more tokens of that same name
        else if ((prevCard != null
            && c.isCreature()
            && prevCard.isCreature()
            && (prevCard.isEquipped() || prevCard.isEnchanted())
            && prevCard.getName().equals(c.getName()))) startANewStack = true;
        else if (prevCard != null
            && c.isCreature()
            && prevCard.isCreature()
            && !prevCard.getName().equals(c.getName())) startANewStack = true;

        if (((c.isAura() && c.isEnchanting()) || (c.isEquipment() && c.isEquipping()))
            && prevCard != null
            && prevCard.isPlaneswalker()) startANewStack = true;

        if (startANewStack) {
          setupConnectedCards(connectedCards);
          connectedCards.clear();

          // Fixed distance if last was a stack, looks a bit nicer
          if (atInStack > 1) {
            x +=
                Math.max(addPanel.getPreferredSize().width, addPanel.getPreferredSize().height)
                    + marginX;
          } else {
            x = nextXIfNotStacked;
          }

          atInStack = 0;
        } else {
          if (i != 0) {
            x += cardOffset;
          }
        }

        nextXIfNotStacked = x + marginX + addPanel.getPreferredSize().width;

        int xLoc = x;

        int yLoc = marginY;
        yLoc += atInStack * cardOffset;

        addPanel.setLocation(new Point(xLoc, yLoc));
        addPanel.setSize(addPanel.getPreferredSize());

        cards.add(addPanel);

        connectedCards.add((CardPanel) addPanel);

        atInStack++;
        prevCard = c;
      }

      setupConnectedCards(connectedCards);
      connectedCards.clear();

      for (int i = cards.size() - 1; i >= 0; i--) {
        JPanel card = cards.get(i);
        // maxX = Math.max(maxX, card.getLocation().x + card.getSize().width + marginX);
        maxY = Math.max(maxY, card.getLocation().y + card.getSize().height + marginY);
        p.add(card);
      }

      maxX = nextXIfNotStacked;

      if (maxX > 0 && maxY > 0) { // p.getSize().width || maxY > p.getSize().height) {
        p.setPreferredSize(new Dimension(maxX, maxY));
      }

    } else {
      JPanel addPanel;
      for (int i = 0; i < list.size(); i++) {
        c = list.get(i);
        addPanel = new CardPanel(c);

        p.add(addPanel);
      }
    }
  } // setupPanel()
  /**
   * setupPanel.
   *
   * @param p a {@link javax.swing.JPanel} object.
   * @param list a {@link java.util.ArrayList} object.
   * @param stack a boolean.
   */
  private static void setupPanel(JPanel p, ArrayList<Card> list, boolean stack) {

    int maxY = 0;
    int maxX = 0;
    // remove all local enchantments

    Card c;
    /*
    for(int i = 0; i < list.size(); i++)
    {
      c = (Card)list.get(i);
      if(c.isLocalEnchantment())
        list.remove(i);
    }

    //add local enchantments to the permanents
    //put local enchantments "next to" the permanent they are enchanting
    //the inner for loop is backward so permanents with more than one local enchantments are in the right order
    Card ca[];
    for(int i = 0; i < list.size(); i++)
    {
      c = (Card)list.get(i);
      if(c.hasAttachedCards())
      {
        ca = c.getAttachedCards();
        for(int inner = ca.length - 1; 0 <= inner; inner--)
          list.add(i + 1, ca[inner]);
      }
    }
    */

    if (stack) {
      // add all Cards in list to the GUI, add arrows to Local Enchantments

      ArrayList<Card> manaPools = getManaPools(list);
      ArrayList<Card> enchantedLands = getEnchantedLands(list);
      ArrayList<Card> basicBlues = getBasics(list, Constant.Color.Blue);
      ArrayList<Card> basicReds = getBasics(list, Constant.Color.Red);
      ArrayList<Card> basicBlacks = getBasics(list, Constant.Color.Black);
      ArrayList<Card> basicGreens = getBasics(list, Constant.Color.Green);
      ArrayList<Card> basicWhites = getBasics(list, Constant.Color.White);
      ArrayList<Card> badlands = getNonBasicLand(list, "Badlands");
      ArrayList<Card> bayou = getNonBasicLand(list, "Bayou");
      ArrayList<Card> plateau = getNonBasicLand(list, "Plateau");
      ArrayList<Card> scrubland = getNonBasicLand(list, "Scrubland");
      ArrayList<Card> savannah = getNonBasicLand(list, "Savannah");
      ArrayList<Card> taiga = getNonBasicLand(list, "Taiga");
      ArrayList<Card> tropicalIsland = getNonBasicLand(list, "Tropical Island");
      ArrayList<Card> tundra = getNonBasicLand(list, "Tundra");
      ArrayList<Card> undergroundSea = getNonBasicLand(list, "Underground Sea");
      ArrayList<Card> volcanicIsland = getNonBasicLand(list, "Volcanic Island");

      ArrayList<Card> nonBasics = getNonBasics(list);

      ArrayList<Card> moxEmerald = getMoxen(list, "Mox Emerald");
      ArrayList<Card> moxJet = getMoxen(list, "Mox Jet");
      ArrayList<Card> moxPearl = getMoxen(list, "Mox Pearl");
      ArrayList<Card> moxRuby = getMoxen(list, "Mox Ruby");
      ArrayList<Card> moxSapphire = getMoxen(list, "Mox Sapphire");
      // ArrayList<Card> moxDiamond = getMoxen(list, "Mox Diamond");

      list = new ArrayList<Card>();
      list.addAll(manaPools);
      list.addAll(enchantedLands);
      list.addAll(basicBlues);
      list.addAll(basicReds);
      list.addAll(basicBlacks);
      list.addAll(basicGreens);
      list.addAll(basicWhites);
      list.addAll(badlands);
      list.addAll(bayou);
      list.addAll(plateau);
      list.addAll(scrubland);
      list.addAll(savannah);
      list.addAll(taiga);
      list.addAll(tropicalIsland);
      list.addAll(tundra);
      list.addAll(undergroundSea);
      list.addAll(volcanicIsland);

      list.addAll(nonBasics);

      list.addAll(moxEmerald);
      list.addAll(moxJet);
      list.addAll(moxPearl);
      list.addAll(moxRuby);
      list.addAll(moxSapphire);
      // list.addAll(moxDiamond);

      int atInStack = 0;

      int marginX = 5;
      int marginY = 5;

      int x = marginX;

      int cardOffset = Constant.Runtime.stackOffset[0];

      String color = "";
      ArrayList<JPanel> cards = new ArrayList<JPanel>();

      ArrayList<CardPanel> connectedCards = new ArrayList<CardPanel>();

      boolean nextEnchanted = false;
      Card prevCard = null;
      int nextXIfNotStacked = 0;
      for (int i = 0; i < list.size(); i++) {
        JPanel addPanel;
        c = list.get(i);

        addPanel = new CardPanel(c);

        boolean startANewStack = false;

        if (!isStackable(c)) {
          startANewStack = true;
        } else {
          String newColor = c.getName(); // CardUtil.getColor(c);

          if (!newColor.equals(color)) {
            startANewStack = true;
            color = newColor;
          }
        }

        if (i == 0) {
          startANewStack = false;
        }

        if (!startANewStack && atInStack == Constant.Runtime.stackSize[0]) {
          startANewStack = true;
        }

        if (c.isAura() && c.isEnchanting() && !nextEnchanted) startANewStack = false;
        else if (c.isAura() && c.isEnchanting()) {
          startANewStack = true;
          nextEnchanted = false;
        }

        if (c.isLand() && c.isEnchanted()) {
          startANewStack = false;
          nextEnchanted = true;
        }

        // very hacky, but this is to ensure enchantment stacking occurs correctly when a land is
        // enchanted, and there are more lands of that same name

        else if ((prevCard != null
            && c.isLand()
            && prevCard.isLand()
            && prevCard.isEnchanted()
            && prevCard.getName().equals(c.getName()))) startANewStack = true;
        else if (prevCard != null
            && c.isLand()
            && prevCard.isLand()
            && !prevCard.getName().equals(c.getName())) startANewStack = true;

        /*
        if (c.getName().equals("Squirrel Nest")) {
            startANewStack = true;
            System.out.println("startANewStack: " + startANewStack);
        }
        */
        if (c.isAura() && c.isEnchanting() && prevCard != null && prevCard instanceof ManaPool)
          startANewStack = true;
        if (c instanceof ManaPool && prevCard instanceof ManaPool && prevCard.isSnow())
          startANewStack = false;

        if (startANewStack) {
          setupConnectedCards(connectedCards);
          connectedCards.clear();

          // Fixed distance if last was a stack, looks a bit nicer
          if (atInStack > 1) {
            x +=
                Math.max(addPanel.getPreferredSize().width, addPanel.getPreferredSize().height)
                    + marginX;
          } else {
            x = nextXIfNotStacked;
          }

          atInStack = 0;
        } else {
          if (i != 0) {
            x += cardOffset;
          }
        }

        nextXIfNotStacked = x + marginX + addPanel.getPreferredSize().width;

        int xLoc = x;

        int yLoc = marginY;
        yLoc += atInStack * cardOffset;

        addPanel.setLocation(new Point(xLoc, yLoc));
        addPanel.setSize(addPanel.getPreferredSize());

        cards.add(addPanel);

        connectedCards.add((CardPanel) addPanel);

        atInStack++;
        prevCard = c;
      }

      setupConnectedCards(connectedCards);
      connectedCards.clear();

      for (int i = cards.size() - 1; i >= 0; i--) {
        JPanel card = cards.get(i);
        // maxX = Math.max(maxX, card.getLocation().x + card.getSize().width + marginX);
        maxY = Math.max(maxY, card.getLocation().y + card.getSize().height + marginY);
        p.add(card);
      }

      maxX = nextXIfNotStacked;

      // System.out.println("x:" + maxX + ", y:" + maxY);
      if (maxX > 0 && maxY > 0) { // p.getSize().width || maxY > p.getSize().height) {
        //        p.setSize(new Dimension(maxX, maxY));
        p.setPreferredSize(new Dimension(maxX, maxY));
      }

    } else {
      // add all Cards in list to the GUI, add arrows to Local Enchantments
      JPanel addPanel;
      for (int i = 0; i < list.size(); i++) {
        c = list.get(i);
        /*if(c.isLocalEnchantment())
          addPanel = getCardPanel(c, "<< " +c.getName());
        else
          addPanel = getCardPanel(c);
          */
        addPanel = new CardPanel(c);

        p.add(addPanel);
      }
    }
  } // setupPanel()