couple of questions

[nobr]hi im makeing a game similar to the game show Are You Smarter Than a Fifth Grader, but im encountering some problems. first of all i need to somehow disable the buttons when they are pressed. i also need to connect the buttons A, B, C, D with the answers on the questions. i know its kind of confusing but im trying my best. thank you and please post any questions.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.event.WindowEvent;

class smarterThanAFifthGrader

{

publicstaticvoid main (String[] args)

{

gameFrame frame =new gameFrame();

frame.addWindowListener

(

new WindowAdapter()

{

publicvoid windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

}

}

class gameFrameextends JFrameimplements ActionListener

{

JPanel pane = (JPanel)getContentPane();

JPanel middleRow = (JPanel)getContentPane();

JPanel bottomRow = (JPanel)getContentPane();

JButton lose =new JButton("Game Over");

JButton btnfgHistory =new JButton("First Grade History");

JPanel gridPane =new JPanel();

public gameFrame()

{

super("Are you Smarter Than a Fifth Grader?");

setSize(500,500);

JPanel pane = (JPanel)getContentPane();

pane.setLayout(new GridLayout(3,1));

JPanel gridPane =new JPanel();

gridPane.setLayout(new GridLayout(5,2));

JPanel middleRow =new JPanel();

middleRow.setLayout(new GridLayout(1,0));

JPanel bottomRow =new JPanel();

bottomRow.setLayout(new GridLayout(4,0));

JButton btnfgHistory =new JButton("First Grade History");

btnfgHistory.addActionListener(this);

gridPane.add(btnfgHistory);

JButton btnfgGeography =new JButton("First Grade Geography");

btnfgGeography.addActionListener (this);

gridPane.add(btnfgGeography);

JButton btnsgGeography =new JButton("Second Grade Geography");

btnsgGeography.addActionListener(this);

gridPane.add(btnsgGeography);

JButton btnsgMath =new JButton("Second Grade Math");

btnsgMath.addActionListener(this);

gridPane.add(btnsgMath);

JButton btntgScience =new JButton("Third Grade Science");

btntgScience.addActionListener(this);

gridPane.add(btntgScience);

JButton btntgMath =new JButton("Third Grade Math");

btntgMath.addActionListener(this);

gridPane.add(btntgMath);

JButton btnfgEnglish =new JButton("Fourth Grade English");

btnfgEnglish.addActionListener(this);

gridPane.add(btnfgEnglish);

JButton btnfougHistory =new JButton("Fourth Grade History");

btnfougHistory.addActionListener(this);

gridPane.add(btnfougHistory);

JButton btnfifgMath =new JButton("Fifth Grade Math");

btnfifgMath.addActionListener(this);

gridPane.add(btnfifgMath);

JButton btnfifgEnglish =new JButton("Fifth Grade English");

btnfifgEnglish.addActionListener(this);

gridPane.add(btnfifgEnglish);

JButton btnAnsA =new JButton("A");

btnAnsA.addActionListener(this);

bottomRow.add(btnAnsA);

JButton btnAnsB =new JButton("B");

btnAnsB.addActionListener (this);

bottomRow.add(btnAnsB);

JButton btnAnsC =new JButton("C");

btnAnsC.addActionListener(this);

bottomRow.add(btnAnsC);

JButton btnAnsD =new JButton("D");

btnAnsD.addActionListener(this);

bottomRow.add(btnAnsD);

JButton lose =new JButton("Game Over");

lose.addActionListener(this);

lose.setVisible(false);

bottomRow.add(lose);

pane.add(gridPane);

setVisible(true);

pane.add(bottomRow);

setVisible(true);

}

publicvoid actionPerformed(ActionEvent e)

{

if(e.getActionCommand().equals("First Grade History"))

{

JLabel fgHistory =new JLabel("<html>Whos was the first Prime Minister <br> A: Jean Chretien <br> B: Mackenzie King <br> C: Robert Borden <br> D: John A Macdonald <html>");

pane.add(fgHistory);

btnfgHistory.setEnabled(false);

setVisible(true);

}

elseif(e.getActionCommand().equals("First Grade Geography"))

{

JLabel fgGeography =new JLabel("What country is this?");

pane.add(fgGeography);

setVisible(true);

}

elseif(e.getActionCommand().equals("Second Grade Geography"))

{

JLabel fgGeography =new JLabel("What country is this?");

pane.add(fgGeography);

setVisible(true);

}

elseif(e.getActionCommand().equals("Second Grade Math"))

{

JLabel sgMath =new JLabel();

sgMath.setText("<html>If Jim has 5 apples and eats one apple every hour and gives his friend one apple after he eats an apple. How many apples would Jim get to eat?</html>");

pane.add(sgMath);

setVisible(true);

}

elseif(e.getActionCommand().equals("Third Grade Science"))

{

JLabel tgScience =new JLabel("");

pane.add (tgScience);

setVisible(true);

}

elseif(e.getActionCommand().equals("Third Grade Math"))

{

}

elseif(e.getActionCommand().equals("Fourth Grade English"))

{

}

elseif(e.getActionCommand().equals("Fourth Grade History"))

{

}

elseif(e.getActionCommand().equals("Fifth Grade Math"))

{

}

elseif( e.getActionCommand().equals("Fifth Grade English"))

{

}

elseif(e.getActionCommand().equals("A"))

{

getContentPane().validate();

}

elseif(e.getActionCommand().equals("B"))

{

lose.setVisible(true);

}

elseif(e.getActionCommand().equals("C"))

{

lose.setVisible(true);

}

elseif(e.getActionCommand().equals("D"))

{

}

}

}

[/nobr]

[11351 byte] By [smahmooda] at [2007-11-27 6:46:57]
# 1
buttonInstance.setEnabled(false); // turn button offbuttonInstance.setEnabled(true);// turn button on
cotton.ma at 2007-7-12 18:19:26 > top of Java-index,Java Essentials,Java Programming...
# 2
i tried setEnabled(false); but it didnt workis buttonInstance an actual command or do i replace it with the name of the button?and where would i add it to the code?
smahmooda at 2007-7-12 18:19:26 > top of Java-index,Java Essentials,Java Programming...
# 3

> i tried setEnabled(false); but it didnt work

What does "didn't work" mean?

> is buttonInstance an actual command or do i replace

> it with the name of the button?

You have to specify the name of the button to disable.

> and where would i add it to the code?

Wherever you want your button disabled :).

kevjavaa at 2007-7-12 18:19:26 > top of Java-index,Java Essentials,Java Programming...
# 4
You actually don't want to connect your buttons directly with answers nor do you want to hardwire your buttons with questions (as I see present in your posted program). You need to think OOP and loose coupling.
petes1234a at 2007-7-12 18:19:26 > top of Java-index,Java Essentials,Java Programming...