Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Netbeans Java Quiz

  • 16-03-2014 7:13pm
    #1
    Registered Users, Registered Users 2 Posts: 2,369 ✭✭✭


    Hey there, I want to create a new JPanels for each question on one single GUI JFrame. For each question I give the user a question in a JTextField and the user needs to click one answer from 4 JButtons.

    So if the user selects the answer I want to link them to a new JPanel which shows them the next question.

    This is a screenshot of what I have so far.

    http://i.gyazo.com/3ce0543b761c04572446d27b53fcf8a5.png


Comments

  • Registered Users, Registered Users 2 Posts: 112 ✭✭Minatauro


    Hi Im very very noob at this java stuff also but what i think you need to research is the CardLayout. Which can be applied to having the jtextfield on jpanels for the question box that switch when the correct button is pressed.

    I found these two helpful for something i was trying to do. Sorry if i cant explain it myself as i am only learning java now myself.

    http://www.youtube.com/watch?v=d-zSU6vNwYw

    http://www.youtube.com/watch?v=sAReaaTxNGU

    hope this small bit helps.


  • Registered Users, Registered Users 2 Posts: 2,369 ✭✭✭LostBoy101


    Minatauro wrote: »
    Hi Im very very noob at this java stuff also but what i think you need to research is the CardLayout. Which can be applied to having the jtextfield on jpanels for the question box that switch when the correct button is pressed.

    I found these two helpful for something i was trying to do. Sorry if i cant explain it myself as i am only learning java now myself.

    http://www.youtube.com/watch?v=d-zSU6vNwYw

    http://www.youtube.com/watch?v=sAReaaTxNGU

    hope this small bit helps.

    Cheers! I managed to use the cardlayout and use some sort of JPanel hierachy. For example created a JPanel with cardlayout and created subclasses of the questions.

    Now I will watch the videos of how to code it.


  • Registered Users, Registered Users 2 Posts: 437 ✭✭t1mm


    I'd do it like this:

    1. ArrayList of Question objects
    2. On application start, set the value of the text on your GUI to the first question in the arraylist.
    3. On application start, set the value of the text on each button to the relevant values from the first Question.
    4. Each time an answer button is pressed, store its value, and load the next question from your arraylist (just replace the values of the GUI elements).


  • Registered Users, Registered Users 2 Posts: 2,369 ✭✭✭LostBoy101


    t1mm wrote: »
    I'd do it like this:

    1. ArrayList of Question objects
    2. On application start, set the value of the text on your GUI to the first question in the arraylist.
    3. On application start, set the value of the text on each button to the relevant values from the first Question.
    4. Each time an answer button is pressed, store its value, and load the next question from your arraylist (just replace the values of the GUI elements).

    I have all my questions in ArrayList. Hmm.. bit confused when you set value of the text on my GUI. Do you mean set the values for answers in the question?


  • Registered Users, Registered Users 2 Posts: 437 ✭✭t1mm


    Given a Question Object with 4 answers, the correct answer, and the question text itself:

    App Start
    jTextField.setText(questionsArrayList.get(i).getQuestion());
    button1.setText(questionsArrayList.get(i).getFirstAnswer());
    (same for the other 3 buttons)
    

    On button press
    answers[questionNumber] = 1;
    questionNumber++
    jTextField.
    
    (Do this for each button - assign a value to each, e.g. topleft=1,topright=2,bottomleft=3,bottomright=4.

    Then go ahead and evaluate all of the correct answers at the end.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,369 ✭✭✭LostBoy101


    Hey me again!

    I've decided just to add the answers to the arrayList to make it easier. However I'm having troubles evaulating the answers at the end. Do I use a loop or just an if statement?


Advertisement