G
gruenerTeppich
Gast
Hallo!
Kann mir jemand erklären, warum diese Applikation nicht läuft?
Ich erhalte immer die Fehlermeldung "Fatal Exception occured. Program will exit." Außerdem ist "main(String[] args)" in Eclipse rot unterstrichen. Den Inhalt habe ich von einer Java-Lern-DVD.
Kann mir jemand erklären, warum diese Applikation nicht läuft?
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Swing_JButton extends JFrame {
private JButton button1, button2;
Swing_JButton() {
super();
this.setTitle("Herzlich willkommen bei Swing!");
this.getContentPane().setLayout(null);
button1 = new JButton("Klick mich!");
button1.setSize(150, 50);
button1.setLocation(10, 10);
button1.setIcon(new ImageIcon("ok.gif"));
button1.setMnemonic(KeyEvent.VK_K);
button2 = new JButton("Oder mich!");
button2.setSize(150, 50);
button2.setLocation(150, 10);
button2.setIcon(new ImageIcon("cancel.gif"));
button2.setMnemonic(KeyEvent.VK_O);
this.getContentPane().add(button1);
this.getContentPane().add(button2);
// Events
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button1.addActionListener(new KnopfAktionen());
button2.addActionListener(new KnopfAktionen());
}
class KnopfAktionen implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == button1.getText()) {
button1.setText("Danke!");
}
if (e.getActionCommand() == button2.getText()) {
button1.setText("Danke!");
}
}
public static void main(String[] args) {
Swing_JButton fenster = new Swing_JButton();
fenster.setSize(300, 100);
fenster.setLocation(200, 100);
fenster.setVisible(true);
}
}
}