Results 1 to 7 of 7

Thread: a quiz program

  1. #1
    tom2zip is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default a quiz program

    what i'm trying to create here is a quiz program
    there are four radio buttons, each representing the possible answers to the question and if i click on a radio button, the next question will show up and so on
    the problem is that i have no idea how to make that happen
    any suggestions?

    Java Code:
    import java.awt.BorderLayout;
    
    
    public class QuestionPage extends JFrame
    {
    
    	private JPanel contentPane;
    	private JTextField txtQuestion;
    
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args)
    	{
    		EventQueue.invokeLater(new Runnable()
    		{
    			public void run()
    			{
    				try
    				{
    					QuestionPage frame = new QuestionPage();
    					frame.setVisible(true);
    				} catch (Exception e)
    				{
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    
    	/**
    	 * Create the frame.
    	 */
    	public QuestionPage()
    	{
    		setTitle("Quiz");
    		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		setBounds(100, 100, 414, 241);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
    		contentPane.setLayout(null);
    		
    		ButtonGroup options = new ButtonGroup();
    		
    		
    		JRadioButton rbOpt1 = new JRadioButton("Option 1");
    		rbOpt1.addMouseListener(new MouseAdapter() {
    		rbOpt1.setBounds(10, 84, 109, 23);
    		options.add(rbOpt1);
    		contentPane.add(rbOpt1);
    		
    		JRadioButton rbOpt2 = new JRadioButton("Option 2");
    		rbOpt2.setBounds(10, 110, 109, 23);
    		options.add(rbOpt2);
    		contentPane.add(rbOpt2);
    		
    		JRadioButton rbOpt3 = new JRadioButton("Option 3");
    		rbOpt3.setBounds(10, 136, 109, 23);
    		options.add(rbOpt3);
    		contentPane.add(rbOpt3);
    		
    		JRadioButton rbOpt4 = new JRadioButton("Option 4");
    		rbOpt4.setBounds(10, 162, 109, 23);
    		options.add(rbOpt4);
    		contentPane.add(rbOpt4);
    		
    		txtQuestion = new JTextField();
    		txtQuestion.setFont(new Font("Tahoma", Font.PLAIN, 18));
    		txtQuestion.setText("Question #1");
    		txtQuestion.setBounds(10, 39, 332, 28);
    		contentPane.add(txtQuestion);
    		txtQuestion.setColumns(10);
    	}
    }
    Last edited by Eranga; 12-15-2011 at 02:53 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: a quiz program

    Please use the code tags when you posting code segments next time. Unformatted codes are really hard to read.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: a quiz program

    Regarding your question,

    1. You must have a way to store already created question and answers. Because you cannot generate question through a code, human interaction is need.
    2. To store questions you can use a database, text file, etc...
    3. In my experience, you can use XML (and XSLT too for formatting). So you can define a patter to store details of each question and work around.
    4. Use of databases can cause lot of performance issues.

  4. #4
    tom2zip is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: a quiz program

    can you explain what XML and XSLT are? sorry i'm new to Java

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: a quiz program

    If you don't know about XSLT just forget about that at the moment. Those are comes to picture when you have to dealing with formatting/styling. With or without XSLT we can do styling, but having it make your life easy.

    However, the knowledge of XML is really valued for all the programmers I think. If you really don't know about that read the following Wiki first of all.

    XML - Wikipedia, the free encyclopedia

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: a quiz program

    Quote Originally Posted by tom2zip View Post
    can you explain what XML and XSLT are? sorry i'm new to Java
    Alex, I'll take "Questions I can answer myself" for 100 thanks.

    What is Google?

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: a quiz program

    Quote Originally Posted by Junky View Post
    Alex, I'll take "Questions I can answer myself" for 100 thanks.
    Good point mate. But that is where I always stuck.

Similar Threads

  1. Help with quiz program
    By askinne2 in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 10:49 PM
  2. quiz program using access as database
    By miinnesh in forum AWT / Swing
    Replies: 5
    Last Post: 03-05-2010, 11:30 AM
  3. quiz program using access as database
    By miinnesh in forum JDBC
    Replies: 0
    Last Post: 03-05-2010, 05:54 AM
  4. Help with quiz
    By khanzaman in forum AWT / Swing
    Replies: 10
    Last Post: 01-19-2009, 07:45 AM
  5. Help pls with a quiz
    By saytri in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •