Help closing frames and disabling frames

Advertisement
November 30

hey, i'm making this type of quiz game and i've got the primary game frame with it's game panel. When the player matches two images on this main panel, another frame with a panel is drawn on top of the main game and asks the user a question, if the user gets the right answer i want it to return back to the game and close the quiz frame. I can't use system.exit(0) when the user gets the correct answer because the whole application shuts down. how do i just close this one? Also, i make a new quiz frame object for each match on the game board, the constructor of the quiz frame takes an int as a parameter which represents the game state and thus which question to ask the user.
So that's just a bit of background information, the two questions i have are:
1. How do i close the quiz frame when the user enters the correct answer without closing the entire game application? As it is my Panel within my quiz frame doing the check to see if the users input is correct, i'd like to be able to close the quiz frame down from this panel. so i'm looking for
something like:
this is just some pseudo code to explain what i want to do
if(answerCorrect) {
this.parentFrame.close(); 
}2. How do disable the primary game while the quiz frame is up and displaying a question to the player? I don't want the player to be able to continue playing the game without first entering the correct answer. and only when they answer correct do I wish the main game to become re-enabled.
If the answers are not simple then i'd be happy to read any links/information which would help.
Thanks a heap i really appreciate it :)

Advertisement

Replay

Encephalopathic wrote:
but a better and more flexible way to implement this is to allow outside objects pass this array into the QuizPanel object, either by its constructor or by a setter method allowing you to use the same QuizPanel class for different data.Ages ago I downloaded an example from these forums which does just that, and it also randomizes the order or the answers. See below -
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SwingConstants;
public class QuizGUI
  private JPanel mainPanel = new JPanel();
  private Question[] questions =
    new Question("How many months in a year?", "12", new String[]
      "1", "Several", "100", "Heck if I know?"
    new Question("Who was buried in Grant's Tomb?", "Grant", new String[]
      "Washington", "Jefferson", "Lincoln", "Mickey Mouse"
    new Question("What's the air-speed velocity of a fully ladden swallow",
        "African or European?", new String[]
          "100 mi/hr", "25 mi/hr", "50 mi/hr", "-10 mi/hr"
    new Question("What color was Washington's white horse?", "White",
        new String[]
          "Blue", "Brown", "Chartreuse", "Mauve"
  private QuestionGUI[] questionGuis = new QuestionGUI[questions.length];
  public QuizGUI()
    JPanel questionPanel = new JPanel(new GridLayout(0, 1, 0, 10));
    for (int i = 0; i < questionGuis.length; i++)
      questionGuis[i] = new QuestionGUI(questions);
JComponent comp = questionGuis[i].getComponent();
comp.setBorder(BorderFactory.createEtchedBorder());
questionPanel.add(comp);
JButton checkAnswersBtn = new JButton("CheckAnswers");
checkAnswersBtn.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
int score = 0;
for (QuestionGUI quest : questionGuis)
if (quest.isSelectionCorrect())
score++;
else
System.out.println("For the question: \"" + quest.getQuestion().getQuestion() + "\",");
System.out.println("\"" + quest.getSelectedString() + "\" is the wrong answer");
System.out.println("The correct answer is: \"" + quest.getQuestion().getCorrectAnswer() + "\"");
System.out.println("Score: " + score);
JPanel btnPanel = new JPanel();
btnPanel.add(checkAnswersBtn);
int ebGap = 10;
mainPanel.setBorder(BorderFactory.createEmptyBorder(ebGap, ebGap, ebGap, ebGap));
mainPanel.setLayout(new BorderLayout());
mainPanel.add(questionPanel, BorderLayout.CENTER);
mainPanel.add(btnPanel, BorderLayout.SOUTH);
public JComponent getComponent()
return mainPanel;
private static void createAndShowUI()
JFrame frame = new JFrame("Quiz");
frame.getContentPane().add(new QuizGUI().getComponent());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args)
java.awt.EventQueue.invokeLater(new Runnable()
public void run()
createAndShowUI();
class QuestionGUI
private JPanel mainPanel = new JPanel();
private Question question;
private ButtonGroup buttonGrp = new ButtonGroup();
public QuestionGUI(Question question)
this.question = question;
JPanel radioPanel = new JPanel(new GridLayout(1, 0, 10, 0));
for (String str : question.getAnswers())
JRadioButton rButton = new JRadioButton(str);
rButton.setActionCommand(str);
radioPanel.add(rButton);
buttonGrp.add(rButton);
mainPanel.setLayout(new BorderLayout(10, 10));
mainPanel.add(new JLabel(question.getQuestion(), SwingConstants.LEFT),
BorderLayout.NORTH);
mainPanel.add(radioPanel, BorderLayout.CENTER);
public Question getQuestion()
return question;
public String getSelectedString()
ButtonModel model = buttonGrp.getSelection();
if (model != null)
return model.getActionCommand();
else
return null;
public boolean isSelectionCorrect()
ButtonModel model = buttonGrp.getSelection();
if (model != null)
return question.isCorrect(model.getActionCommand());
return false;
public JComponent getComponent()
return mainPanel;
class Question
private String question;
private String answer;
private List<String> answers = new ArrayList<String>();
public Question(String q, String answer, String[] badAnswers)
question = q;
this.answer = answer;
for (String string : badAnswers)
answers.add(string);
answers.add(answer);
Collections.shuffle(answers);
public String getQuestion()
return question;
public String[] getAnswers()
return answers.toArray(new String[0]);
public String getCorrectAnswer()
return answer;
public boolean isCorrect(String selection)
return answer.equals(selection);

View 15 Replies

HELP: CLOSING MAIL AND GOOGLE MAPS

November 30

Dear guys, My 3gs suffer from battery drain caused by background 3g traffic data activity. Even if I have no background running app, my phone keeps sending receiving huge mb of data. I've downloaded from appstore an app, system lite, which has reveal

View All Replies

Copy and paste frames is CS3

October 11

I'm going from mx to cs3 and can't find the copy and paste frames option that used to be in the edit menu. Can anyone help with that?select all the frames you want to copy, right click, copy frames.. in new doc, right click on a frame, paste framesRe

View All Replies

Slow drive and dropped frames

November 30

Hi help! I've just finished an edit using fcp 6 .. 1.5hrs long / using 3 camera multiclip .. no problems. I've cleared that out, and this time have a 2.5hr project / similar 3 camera multiclip, and I'm getting error messages every 10 secs, about slow

View All Replies

In an inbuild example of can .. that CAN transmit periodic vi .. i am unable to understand how the extended and standard frame is set?

October 11

In an inbuild example of can .. that CAN transmit  periodic vi .. i am unable to understand how the extended and standard frame is set? plz help me .. stuck up very badly thanks mahadev Solved! Go to Solution.I suggest this KB which explains usage of

View All Replies

Please help with integer variable matching frame numbers

November 30

hi :-) , could someone please hepl a newbie ? I am trying to write a short AS3 script in CS4 that allows me to step backwards and forwards  through an animation. I have a stop button a play button , rewind button and a forward button. the buttons wor

View All Replies

JSF seems not to support the use of the back buttons and html frames.

October 11

I�m having the following problem. I have a JSP which contains a button that register a listener. Here is part of the code: <h:command_hyperlink label="<%=engineBean.getId()%>" commandName="<%=engineBean.getId()%>"> &l

View All Replies

Pal transfers and duplicate frames

November 30

here in china... editing a 35mm feature.... editing in beijing.... shoot is in henan provence and the lab and transfer house is in shanghai... the transfer house is transfering to dvcam with the following settings: timecode @ 25fps and telecine or "t

View All Replies

Why Frame and Dialog cannot be added as Component using add method?

November 30

add method signature is add(Component c) when we try to add window or its subclasses ie Frame and Dialog using add method an IllegalArgumentException is thrown .WHY? Why Frame and Dialog cannot be added as Component using add method? Is it true that

View All Replies

Playback of clips only plays between 4 and 12 frames

October 11

Hi all, I am fairly new to Premiere, have used After Effects CS4 to produce some clips, but need something that handles editing better, and I thought I would give Premiere CS4 a try. Unfortunately, I can't get Source or Sequence preview working.  I c

View All Replies

AE CC 2014 Corrupted and Glitched frames when rendering to Quicktime

October 11

Ever since upgrading to the newest version of After Effects, I've been getting corrupted and glitched frames when rendering videos with a Quicktime holder.  My normal workflow is rendering the video straight out of AE, but it also happens when render

View All Replies

Since upgrading to the new firefox, pictures on facebook do not load automatically. I have to click on the frame and select view image in order to see the photos. Do you have a solution to make the photos autoload?

November 30

Since upgrading to the new firefox, pictures on facebook do not load automatically. I have to click on the frame and select view image in order to see the photos. Do you have a solution to make the photos autoload?https://support.mozilla.com/en-US/qu

View All Replies

SOMEONE PLEASE HELP ME THIS IS MY FIRST TIME DOING THIS MY IPOD IS DISABLED AND IT SAID CONNECT TO I TUNES I DID THAT AND ITS NOT WORKING HELP ME PLEASE AND THANK U

November 30

SOMEONE PLEASE HELP ME THIS IS MY FIRST TIME DOING THIS MY IPOD IS DISABLED AND IT SAID CONNECT TO I TUNES I DID THAT AND ITS NOT WORKING HELP ME PLEASE AND THANK UPlease turn off your caps lock. See http://support.apple.com/kb/HT1212.Read other 3 an

View All Replies

Cut and Paste: Frame and Content Size Auto Changes

November 30

I'm working in InDesign CS2 and am having this reoccurring problem. When I cut and paste frames with placed images (or pull images from a library) the frame and image will both expand to between 300%-3,000%. As you can imagine, it's very frustrating

View All Replies

I converted video into frames. There is a big difference between video size(700 MB) and All frames s

November 30

I converted video into frames. There is a big difference between video size(700 MB) and All frames size(More than 5 GB). What are the reasons ?Please, are you sure that you posted this in the correct forum? This is the Adobe Captivate forum, not a fo

View All Replies

I want to check the main diffrence in Pop up block enabled and disabled.But,i don't get any difference.Would u please help me to understand the difference using one practical example of website

October 11

I want to check the main diffrence in Pop up block enabled and disabled.But,i don't get any difference.Would u please help me to understand the difference using one practical example of websiteHere's two popup test sites. http://www.kephyr.com/popupk

View All Replies

Red frames and MXF decode error

October 11

Hi there, I have Premiere Pro CC and running Mac OSX 10.9.5. I have one long 32 minute long C300 MXF clip in my timeline which seems to be fine until around the 26 minute mark, where the entire frame goes red. The audio still works, but I can't see a

View All Replies

Hidden Frames and Stokes in author

November 30

Hi- I am thinking that the same hidden frames and strokes available to iwork 09 are available to ibook author. I am still trying to find the support files for author and see if they are there. If not it might be possible to copy them from iwork into

View All Replies

Frames and Fields?

November 30

What is the relationship between frames and fields with regards to DV? Why is video shot at 60i also considered 30 fps in Final Cut Pro? Thanks.I believe two interlaced fields equal 1 frame of video. And if you're teaching the subject you may want to

View All Replies

How to take input in one frame and display it in other frame of  same page?

November 30

I need to take input (text) for the comment field in one of the frames and when submit button is pressed it should be displayed in the other frame on the same page. I am able to get the input from the user but its not reflected in the other frame whi

View All Replies

Tags:

  1. aplicativos de 2 dolares na app store
  2. descargar iBooks 3.1.1 .ipa
  3. apple tv hulu no signal
  4. update eban-rlwrt pr sap
  5. badi or bte in sap afab transaction
  6. imovie program for a1151
  7. Neha jpx pothos
  8. package4uu
  9. barnduu
  10. новости челябинск мир 74
Copyrights 2019 Fcffair BigData Resource, All rights reserved