0

This is what I have in the main class:

public static void main(String[] args) {

        final login login = new login();                            
        login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        login.setVisible(true);
        login.setResizable(false);

        login.btnEnter.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e) {

            login.inputText.getText();

            new crosswordWindow().setVisible(true);
            login.dispose();
            }
        });


    }

*there is a third class called login, where the jTextField is.

The login.inputText.getText(); should set the value in this JLabel (in the class called crosswordWindow):

    public class crosswordWindow extends JFrame {
    ...

        public crosswordWindow() {
        ...
            userName = new JLabel(userName.setText(login.inputText.getText())); 
        }
    }

But I get this error "non-static variable inputText cannot be referenced from a static context, void type not allowed here"

What am I doing wrong?

3
Contributors
2
Replies
16
Views
2 Years
Discussion Span
Last Post by Phaelax
1

What you are doing wrong, is not understanding the basics first.
login login = new login();

Right there is your problem. Naming conventions, which tell you it should have been:

Login login = new Login();

(which also would have solved your issue) aside: the JVM thinks you are calling it by the classname. Never give your instance the same name as your class. At the very least make sure the first character is lowercase in the variable name, and uppercase in the actual classname.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.