I sometimes see code like this:
new myJFrame().setVisible(true);
I don't exactly know how it works, but it actually creates a myJFrame
and sets it visible, as an alternative to setting it visible on its constructor.
What I would like to know is if there would be a way to do this on a JMenuItem or JButton to automatically assign it an ActionListener without having to explicitly declaring it first, as in:
myJMenu.add(new JMenuItem("Item").addActionListener(myActionListener));
Which, as far as I've tried, doesn't work.
I don't exactly need it to work, I would just like to know if it is possible, for it would save me some good time.
Thanks in advance.