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?

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.