0
enter coclass Gamehandler extends JFrame implements ActionListener {
//questions
JPanel qpanel = new JPanel();
//answers
JPanel aPanel = new JPanel();
JRadioButton[] responses;
ButtonGroup group = new ButtonGroup();
//bottom
JPanel botPanel = new JPanel();
JButton next = new JButton("next");
JButton finish = new JButton("Finish");
static String guess= " ";
readExcel re = new readExcel();
JLabel label = new JLabel();
public void actionPerformed(ActionEvent event) {
    re.readExcel1();
    Random rm = new Random();
    int radiobuttonsize = readExcel.ColumnTwo.size();
    radioButtons rbs = new radioButtons();
    scoreTest   sr = new scoreTest();
    responses = new JRadioButton[readExcel.ColumnTwo.size()];
    //adds my radio buttons 
    //adds action listeneners 
    //adds get actions
    for(int i=0;i<readExcel.ColumnTwo.size();i++){
        responses[i]=new JRadioButton(readExcel.ColumnTwo.get(i));
        group.add(responses[i]);
        aPanel.add(responses[i]);
        responses[i].addActionListener(rbs);
       responses[i].setActionCommand (String.valueOf(i));
   Object selection  =    responses[0].getAction();

    }

   int randomguessArray = rm.nextInt(radiobuttonsize);
    guess =  readExcel.ColumnOne.get(randomguessArray);
    label = new JLabel();
    label.setText(guess);
    qpanel.add(label);
    JFrame frame = new JFrame("Test");
    frame.setSize(400, 300);
    frame.setResizable(true);
    frame.setVisible(true);
    frame.add(aPanel);
    botPanel.add(next);
    botPanel.add(finish);
    frame.getContentPane().add(qpanel,BorderLayout.NORTH);
    frame.getContentPane().add(aPanel,BorderLayout.CENTER);
    frame.getContentPane().add(botPanel,BorderLayout.SOUTH);
    next.addActionListener(sr);

}

public void changeText(){
 label.setText("Work");
 System.out.print("hello");

}

I Just want to add an actionlistener to my JButton and then be able to change the JLabel in my same Frame here. This is critical part of my program. It seems straight forward and I honestly Can't figure it out.Perhaps it's because it's 3:53am and I just worked 8 hours. I would love to have a fresh pair of eyes on my code.

Louis345
  • 700
  • 2
  • 11
  • 38
  • I have read over countless material and have no Idea on why my code isn't working. Unsure on what I would have to do to get a reply. Is my code structured is that why? I really am spending a lot of time on this one issue and in my mind it should work. – Louis345 Aug 15 '13 at 22:01

1 Answers1

-1

In case anyone in 2014 is still having the same issue, the method revalidate() should come in handy.

j-i-l
  • 10,281
  • 3
  • 53
  • 70
Jared
  • 1
  • It's not clear why calling `revalidate()` would help change label text. The OP has code to call `setText()` in a function, but is never calling that function. – nobody Aug 20 '14 at 21:35