i'm using a for loop to iterate through an Arraylist of objects...
each object is a new window, and only want the for loop to continue after I close each new object..
i can't figure out how to do that, anyone got an idea?
here's where the for loop is.
Code:
public void actionPerformed (ActionEvent guiEvent)
{
if (guiEvent.getActionCommand ().equals("Add"))
{ // determine origin of event
if (choice1Prompt.getText().equals(answerPrompt.getText()))
{
Card localCard = new Card();
localCard.setQuestion(questionPrompt.getText());
localCard.setChoice1(choice1Prompt.getText());
localCard.setChoice2(choice2Prompt.getText());
localCard.setChoice3(choice3Prompt.getText());
localCard.setChoice4(choice4Prompt.getText());
localCard.setAnswer(answerPrompt.getText());
cardList.add(localCard); // create cardList arrayList element object
}
else if (choice2Prompt.getText().equals(answerPrompt.getText()))
{
Card localCard = new Card();
localCard.setQuestion(questionPrompt.getText());
localCard.setChoice1(choice1Prompt.getText());
localCard.setChoice2(choice2Prompt.getText());
localCard.setChoice3(choice3Prompt.getText());
localCard.setChoice4(choice4Prompt.getText());
localCard.setAnswer(answerPrompt.getText());
cardList.add(localCard); // create cardList arrayList element object
}
else if (choice3Prompt.getText().equals(answerPrompt.getText()))
{
Card localCard = new Card();
localCard.setQuestion(questionPrompt.getText());
localCard.setChoice1(choice1Prompt.getText());
localCard.setChoice2(choice2Prompt.getText());
localCard.setChoice3(choice3Prompt.getText());
localCard.setChoice4(choice4Prompt.getText());
localCard.setAnswer(answerPrompt.getText());
cardList.add(localCard); // create cardList arrayList element object
}
else if(choice4Prompt.getText().equals(answerPrompt.getText()))
{
Card localCard = new Card();
localCard.setQuestion(questionPrompt.getText());
localCard.setChoice1(choice1Prompt.getText());
localCard.setChoice2(choice2Prompt.getText());
localCard.setChoice3(choice3Prompt.getText());
localCard.setChoice4(choice4Prompt.getText());
localCard.setAnswer(answerPrompt.getText());
cardList.add(localCard); // create cardList arrayList element object
}
else
{
JOptionPane.showMessageDialog(null, "Answer does not equal one of the choices.\nYou must type in an answer equal to one of the choices.");
}
// reinitialize input fields
answerPrompt.setText("... enter answer...");
answerPrompt.selectAll();
answerPrompt.requestFocus();
}
else if (guiEvent.getActionCommand().equals("Use FlashCards"))
{ // determine origin of event
boolean finished = false;
if (!(cardList.isEmpty()))
{
for (Iterator<Card> count = cardList.iterator(); count.hasNext();)
{
Card localCard = (Card)count.next();
CardPanel localPanel = new CardPanel(localCard);
}
}
else
{
JOptionPane.showMessageDialog (null, "No FlashCards Loaded!");
}
}
else if (guiEvent.getActionCommand().equals("Exit"))
{
System.out.println("\nThank you and good bye!\n");
System.exit(0); // terminate program normally
}
}
I didn't really look at all the code.. but from reading the question:
could you not just say something to the effect of:
while(theArrayList.get(i).isVisible() == true){}
which would loop until the window was closed. Or you could do it more eloquently with WindowClosing events.. but it seems like the first option would work
12-14-2005, 10:22 AM
naazrael
well, i'll check out that while loop...
i can't compile anything right now, so yeah.
but, just to clarify, i want this code:
Code:
for (Iterator<Card> count = cardList.iterator(); count.hasNext();)
{
Card localCard = (Card)count.next();
CardPanel localPanel = new CardPanel(localCard);
}
the localCard just stores the data, and the localPanel is the GUI for localCard.
i want this code to create a localPanel object, and only create a new object after that first localPanel is closed.