Как вариант можно сделать ButtonActionListener package-private классом
public class OOP {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(400, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setLayout(new GridBagLayout());
JTextField textf = new JTextField();
JTextField textf2 = new JTextField();
JButton Mybutton = new JButton("Start");
frame.add(textf, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(2, 2, 2, 2), 0, 0));
frame.add(textf2, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(2, 2, 2, 2), 0, 0));
frame.add(Mybutton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(1, 2, 2, 2), 0, 0));
Mybutton.addActionListener(new ButtonActionListener()); // Ошибка
frame.setVisible(true);
frame.pack();
}
}
class ButtonActionListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Messege box");
}
}