Question Frames

connecting 2 question frame with next button

Page 1 of 1

5 Replies - 987 Views - Last Post: 30 August 2009 - 05:08 PM Rate Topic: -----

#1 gururaghava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-August 09

Question Frames

Post icon  Posted 22 August 2009 - 08:03 AM

 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class question extends JFrame implements ActionListener

{
	 JButton jba,jbb;
	 JRadioButton jrb1,jrb2;
	 public question()

	{
		JFrame jf=new JFrame("Aptitude Test");
		jf.setLayout(null);
		jf.setSize(400,200);
		
		Label qn1=new Label("Question no. 1");
		Label q1=new Label("Asia is the largest continent in the world?");
		qn1.setForeground(Color.black);
		qn1.setFont(new Font("SansSerif", Font.PLAIN, 15));
		q1.setForeground(Color.blue);
		q1.setFont(new Font("SansSerif", Font.PLAIN, 12));
		qn1.setBounds( 125,15, 200,20);
		q1.setBounds( 55,40, 500,30);		
		jf.add(qn1);
		jf.add(q1);

		jba=new JButton("Next");
		jf.add(jba);
		jba.addActionListener(this);
		jbb=new JButton("Quit");
		jf.add(jbb);
		jbb.addActionListener(this);
		jba.setBounds(50,130,100,20);
		jbb.setBounds(220,130,100,20);

		jrb1=new JRadioButton("True");
		jrb2=new JRadioButton("False"); 
		
		jrb1.setBounds(110,70,60,50);
		jrb2.setBounds(180,70,70,50);
		
		jf.add(jrb1);
		jf.add(jrb2);
				
		jf.show();

   }   

public void actionPerformed(ActionEvent e)

	{	
	
			if (e.getSource()==jbb)
						{
							System.exit(0);
						}

	}						

}

class question1 extends JFrame implements ActionListener

{
	 JButton jba,jbb;
	 JRadioButton jrb1,jrb2;
	 public question1()

	{
		JFrame jf=new JFrame("Aptitude Test");
		jf.setLayout(null);
		jf.setSize(400,200);
		
		Label qn1=new Label("Question no. 2");
		Label q1=new Label("Cardiology deals with the treatment of lungs?");
		qn1.setForeground(Color.black);
		qn1.setFont(new Font("SansSerif", Font.PLAIN, 15));
		q1.setForeground(Color.blue);
		q1.setFont(new Font("SansSerif", Font.PLAIN, 12));
		qn1.setBounds( 125,15, 200,20);
		q1.setBounds( 55,40, 500,30);		
		jf.add(qn1);
		jf.add(q1);

		jba=new JButton("Next");
		jf.add(jba);
		jba.addActionListener(this);
		jbb=new JButton("Quit");
		jf.add(jbb);
		jbb.addActionListener(this);
		jba.setBounds(50,130,100,20);
		jbb.setBounds(220,130,100,20);

		jrb1=new JRadioButton("True");
		jrb2=new JRadioButton("False"); 
		
		jrb1.setBounds(110,70,60,50);
		jrb2.setBounds(180,70,70,50);
		
		jf.add(jrb1);
		jf.add(jrb2);
				
		jf.show();

   }

public void actionPerformed(ActionEvent e)

	{	
	
			if (e.getSource()==jbb)
						{
							System.exit(0);
						}

	}	

}

class javaexam
{
	public static void main(String arg[])
	{

		question q=new question();
	}	

}




Is This A Good Question/Topic? 0
  • +

Replies To: Question Frames

#2 chili5  Icon User is offline

  • D.I.C Lover

Reputation: 20
  • View blog
  • Posts: 1,144
  • Joined: 28-December 07

Re: Question Frames

Posted 22 August 2009 - 08:12 AM

Do you mean when the user clicks on a button, you want them to go to the next form?

If so:

btnNextActionPerformed() {
new question2().setVisible(true);
}



I don't know the exact syntax, I just use Netbeans to generate the methods for me.

In the actionPerformed method, just create a new instance of question2 and call setVisible.

If this isn't what you meant, please explain. You have to explain your problem and post your code.
Was This Post Helpful? 0
  • +
  • -

#3 gururaghava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-August 09

Re: Question Frames

Posted 22 August 2009 - 08:19 AM

View Postchili5, on 22 Aug, 2009 - 07:12 AM, said:

Do you mean when the user clicks on a button, you want them to go to the next form?

If so:

btnNextActionPerformed() {
new question2().setVisible(true);
}



I don't know the exact syntax, I just use Netbeans to generate the methods for me.

In the actionPerformed method, just create a new instance of question2 and call setVisible.

If this isn't what you meant, please explain. You have to explain your problem and post your code.



Actually this frame is an aptitude test taking frame, my query is 

1. to select one of the answer buttons "true" or "false" and once one of them is selected, the other button should get deactivated.

2. after answering the question if i click the next option it should go to the next frame containg next question (qtn 2).

this is what i'm trying to do.



Was This Post Helpful? 0
  • +
  • -

#4 gururaghava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-August 09

Re: Question Frames

Posted 30 August 2009 - 10:40 AM

Thanks a lot
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10771
  • View blog
  • Posts: 40,102
  • Joined: 27-December 08

Re: Question Frames

Posted 30 August 2009 - 10:47 AM

If the layout for the various questions is the same, you can simply update the text on the JLabel and re-enable to disabled button. It would make things a lot easier than designing 100 or so JFrames and JPanels.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Question Frames

Posted 30 August 2009 - 05:08 PM

You have a serious architecture problem
if question is already a JFrame

class question extends JFrame implements ActionListener


why do you build another JFrame into it ?

		JFrame jf=new JFrame("Aptitude Test");
		jf.setLayout(null);
		jf.setSize(400,200);



you cannot put a JFrame inside another one anyhow

		setLayout(null);
		setSize(400,200);
		
		Label qn1=new Label("Question no. 2");
		Label q1=new Label("Cardiology deals with the treatment of lungs?");
		....
		q1.setBounds( 55,40, 500,30);		
		jadd(qn1);
		jadd(q1);

		jba=new JButton("Next");
		add(jba);
		jba.addActionListener(this);
		jbb=new JButton("Quit");
		add(jbb);
		jbb.addActionListener(this);
		jba.setBounds(50,130,100,20);
		jbb.setBounds(220,130,100,20);

		jrb1=new JRadioButton("True");
		jrb2=new JRadioButton("False"); 
		
		jrb1.setBounds(110,70,60,50);
		jrb2.setBounds(180,70,70,50);
		
		add(jrb1);
		add(jrb2);
				
		show();	// deprecated should be:  setVisible(true);

   }


This post has been edited by pbl: 30 August 2009 - 05:14 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1