wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes beginner question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "beginner question" Watch "beginner question" New topic
Author

beginner question

taha khalid
Greenhorn

Joined: May 22, 2012
Posts: 5
Hi guys,

this is my first question in javaranch.. I'm new here.
I'm trying to design a project in java as a test project. i.e. you create account in the program and enter to answer few questions. the problem I have when creating the Jframe for the questions.
it suppose to have a question (as JLabel) that change whenever I click next to take the other question from MS database. and the radio button selected will be saved in an array to be compared later at the end of questions with the right answers ..

the code I wrote for the button action is






the code is not working before I added the if the code change the question whenever I hit the button but after adding the if it stopped from working .. any advice ... thanks a lot for help

[Added code tags - see UseCodeTags for details]


[Thumbnail for java.JPG]

William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

Welcome,

Look at what you are doing,

No matter what is selected rs.next() is called and then question.setText(rs.getString("question"));

This will always return the same result!

WP
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

Hi Taha. Welcome to the Ranch!

I've got an idea what the problem might be (though that might just be because of code that's missing from the bit you've posted), but the first thing you need to fix is this:
Never do this! At the moment you are catching any exceptions that happen, and completely ignoring them. It's likely that there's an exception being thrown that would tell you exactly what's gone wrong and what line it's happened on, but with an empty catch block you're deliberately hiding this useful information. At the very least print out the stack trace.

Change that, and let us know if you get details of any error.
taha khalid
Greenhorn

Joined: May 22, 2012
Posts: 5
William P O'Sullivan wrote:Welcome,

Look at what you are doing,

No matter what is selected rs.next() is called and then question.setText(rs.getString("question"));

This will always return the same result!

WP




yes this is my plan whatever radio button is selected the next question will be shown but the answer will be saved in an array for checking later....
taha khalid
Greenhorn

Joined: May 22, 2012
Posts: 5
Matthew Brown wrote:Hi Taha. Welcome to the Ranch!

I've got an idea what the problem might be (though that might just be because of code that's missing from the bit you've posted), but the first thing you need to fix is this:
Never do this! At the moment you are catching any exceptions that happen, and completely ignoring them. It's likely that there's an exception being thrown that would tell you exactly what's gone wrong and what line it's happened on, but with an empty catch block you're deliberately hiding this useful information. At the very least print out the stack trace.

Change that, and let us know if you get details of any error.



I will try to put some exceptions handling and check it ... thanks a lot for your help
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
another way to approach this (easier perhaps) is to create a collection of Question objects,
and read all the db stuff into those objects when the program opens.

the Question object could have:
the question to display
the choices to display
the user's answer/selection
the correct answer if a quiz-type question

click 'next':
the user's selection is recorded in the currently displayed Question object
the radioButton selection is cleared
the text of the label and radioButtons change to that of the next Question object
(you could even disable the 'next' button until a selection is made)

at the end you iterate the Question object collection for all the user's answers/selections
taha khalid
Greenhorn

Joined: May 22, 2012
Posts: 5
Michael Dunn wrote:another way to approach this (easier perhaps) is to create a collection of Question objects,
and read all the db stuff into those objects when the program opens.

the Question object could have:
the question to display
the choices to display
the user's answer/selection
the correct answer if a quiz-type question

click 'next':
the user's selection is recorded in the currently displayed Question object
the radioButton selection is cleared
the text of the label and radioButtons change to that of the next Question object
(you could even disable the 'next' button until a selection is made)

at the end you iterate the Question object collection for all the user's answers/selections







yes this is really a better way to do it ... but the problem im not sure that i will manage to make it as an executable code (i.e. I doubt I will know how to write it without errors) but thanks a lot for this idea
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: beginner question
 
Similar Threads
First 10 digits of the sum of 100 50 digit numbers (Project Euler # 13)
question from the real test
Design Decisions Document
Call_Method_Problem
The questions have relevance to your project implementation?