Hi!
Ich wollte Actionlistener in meinen JFrames so implementieren, wie ich es in "The Java Tutorial" gesehen habe.
Das Problem: ich kann nicht kompilieren, Fehlemeldung:
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (CNewSaalWin)
Ich hab das ganze so gemacht:
---------------------------------------------------------------------
public class CMyWin extends JFrame {
// Constants for Action Commands
protected final static String SPEICHERN = "speichern";
// Panels...
private JPanel contentPane = null;
private javax.swing.JPanel jPanel = null;
private javax.swing.JPanel jPanel1 = null;
...
...
public CMyWin() {
super();
initialize();
}
private void initialize() {
this.setContentPane(getMyContentPane());
this.setName("JFrame2");
this.setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE);
this.setBounds(85, 65, 305, 440);
this.setTitle("Hallo");
this.setResizable(true);
}
...
// Panel-getter usw...
...
private javax.swing.JButton getJButton1() {
if(jButton1 == null) {
jButton1 = new javax.swing.JButton("Saal speichern");
jButton1.setPreferredSize(new java.awt.Dimension(120,25));
jButton1.setActionCommand(SAAL_SPEICHERN);
jButton1.addActionListener(this);
}
return jButton1;
}
...
...
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
//Handle Button-Events
if (SAAL_SPEICHERN.equals(cmd)) {
speichernActionPerformed();
}
}
}
---------------------------------------------------------------------
Und in der Zeile
jButton1.addActionListener(this);
bekomme ich eben diese Fehlermeldung mit "is not applicable...".
Was mache ich falsch?
In dem Java Tutorial ist das wiegesagt ähnlich gelöst. Liegts daran, dass ich keinen JFrame definiere sondern ihn erweitere? Kenn mich leider nicht soooo gut aus...!
Danke schon mal im Voraus für eure Ideen,
cu, Tobias