user2670495
user2670495

Reputation: 27

How can I access a method of owner JFrame in a JDialog

I have to create a login JFrame and I need username in all the JDialogs that are owned by JFrame. How should I implement this?

I tried the following code.

class MyFrame extends Jframe {

    public getusername() {
        return username;
    }

    createGui() {
        JButton btnsubmit;
        btnsubmit.addActionListener(new ActionListener() {
            void actionPerformed(ActionEvent e) {
                new MyJDialog(MyFrame.this);
            }
        });
    }
}

in the JDialog I am trying to use getusername() in this way

MyJDialog(JFrame frame) {
    super(frame);
    String us=frame.getusername();
}

but it is not working. What am I doing wrong?

Upvotes: 2

Views: 373

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347314

getusername is not a valid method for JFrame.

You should be specifying the concrete implementation within the dialogs constructor...

MyJDialog(MyFrame frame) {...}

Upvotes: 2

Related Questions