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");

}

我只想在我的 JButton 中添加一个动作监听器,然后能够在我的同一个框架中更改 JLabel。这是我的程序的关键部分。这似乎很简单,老实说我无法弄清楚。也许是因为现在是凌晨 3 点 53 分,而我只工作了 8 个小时。我很想对我的代码有一双新的眼睛。

4

1 回答 1

-1

如果 2014 年的任何人仍然遇到同样的问题,那么该方法revalidate()应该会派上用场。

于 2014-08-20T21:06:18.180 回答