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();
}
}
Question Framesconnecting 2 question frame with next button
Page 1 of 1
5 Replies - 722 Views - Last Post: 30 August 2009 - 05:08 PM
#1
Question Frames
Posted 22 August 2009 - 08:03 AM
Replies To: Question Frames
#2
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:
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.
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.
#3
Re: Question Frames
Posted 22 August 2009 - 08:19 AM
chili5, 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:
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.
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.
#5
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.
#6
Re: Question Frames
Posted 30 August 2009 - 05:08 PM
You have a serious architecture problem
if question is already a JFrame
why do you build another JFrame into it ?
you cannot put a JFrame inside another one anyhow
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
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|