I hope I didn't add to much of my code. So I added an actionlistener to the JButton and when it's pressed I want it to update the JLabel in the JFrame. I am unsure why this is not working correctly. I looked through a lot of notes and could not find anything that would help me. There is no errors, it just doesn't update. I am new to programming and thought I this part would be easy.class 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(); JFrame frame = new JFrame("Test"); public void actionPerformed(ActionEvent event) { re.readExcel2(); Random rm = new Random(); int radiobuttonsize = readExcel.ColumnTwo2.size(); System.out.print("this is the size ofthe radiobuttonsize"+radiobuttonsize); radioButtons rbs = new radioButtons(); scoreTest sr = new scoreTest(); responses = new JRadioButton[readExcel.ColumnTwo2.size()]; //adds my radio buttons //adds action listeneners //adds get actions for (int i = 0; i < readExcel.ColumnTwo2.size(); i++) { responses[i] = new JRadioButton(readExcel.ColumnTwo2.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.ColumnOne1.get(randomguessArray); label = new JLabel(); label.setText("What does this mean " + " " + guess); qpanel.add(label); 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); String event1 = event.getActionCommand(); System.out.println("This is the event1"+event1); } public void changeText() { label.setText("Work"); label.revalidate(); } } //next button changes the label class scoreTest extends JFrame implements ActionListener { public void actionPerformed(ActionEvent event) { Gamehandler gr = new Gamehandler(); gr.changeText(); } }
I have tried to update the panel with the new label and still nothing. I hope you can point me in the right direction.