ciao a tutti!!
sto imparando a programmare in java.
fino ad aggiungere label e button ok.
ma ora ho un problema, vorrei assegnare un evento al button.
ho fatto questo codice:
codice:
import javax.swing.*;
public class swing {
	public static void main(String[] args){
		JFrame frame = new JFrame("Test");
		frame.setVisible(true);
		frame.setSize(200,200);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		frame.add(panel);
		
		private class MyButtonListener implements ActionListener {
			public void actionPerformed(ActionEvent evt) {
				System.out.print("ciao ita");
			}
		}
		
		JButton button = new JButton("Hello again");
		MyButtonListener listener = new MyButtonListener();
		button.addActionListener(listener);		
	}
}
ERRORE: Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Illegal modifier for the local class MyButtonListener; only abstract or final is permitted
ActionListener cannot be resolved to a type
ActionEvent cannot be resolved to a type
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (MyButtonListener)

at swing.main(swing.java:12)


Linea 12: private class MyButtonListener implements ActionListener {