Hello, I'm in a pickle.

(Please observe the code) In the actionPerformed method, I don't know how I can get the value of the variable 'minutes'.

I can get 'hours' by e.getActionCommand(), but can't do minutes that way. I need to get both 'hours' and 'minutes' at the same action.

Please help.

import java.awt.FlowLayout;     
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;

public class OuterClass extends JFrame{

    private JLabel hours;
    private JLabel minutes;

    public OuterClass(){

        hours = new JLabel("Hours?");
        minutes = new JLabel("Minutes?");


        InnerClass actionHandler = new InnerClass();


    private class InnerClass implements ActionListener{

        public void actionPerformed(ActionEvent e){

            String output = "";
            String minutes = "";

            if(e.getSource() == hours){
                output = e.getActionCommand();
                minutes =   // ??????? How do I get the minutes here??

This is really confused. You need to stop coding for a minute or two and think about what you are doing.
You have 2 JLabels, but then you add action listeners as if they were buttons, then you try to get two Strings from them as if they were JTextFields.
If you want to get user input then the obvuious thing is to add two JTextFields and an "OK" JButton. In the button's action performed method you can use getText() for the two text fields to get the user's input.

Sorry, my mistake. Yes, I meant JTextFields, and not JLabels; I have tried to correct them but can't (maybe you can, as a mod?) .

And I don't want to add in a JButton; there must be a solution without one! Cheers.

This article has been dead for over six months. Start a new discussion instead.