Hallo...
Offensichtlich gibt es noch immer einige grundlegende Dinge, die ich in Java noch nicht verstanden habe.. Beispielsweise jammert Eclipse im Folgenden Codebeispiel mit der Info "Cannot instantiate the type ActionListener" und markiert mir dabei
new ActionListener(this));
Weiss jemand, warum dies so ist??
lg,
- alex
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Gui implements ActionListener{
public void guiStart() {
JFrame frame = new JFrame("Mein Fenster");
//2. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//JButton startButton = new JButton("ok");
JButton button = new JButton("ok");
frame.getContentPane().add(new JButton("OK"));
button.addActionListener(new ActionListener(this));
//4. Size the frame.
frame.pack();
//5. Show it.
frame.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("OK");
}
}