Code Error Java?
public class Main {
public static void main(String[] args) {
GUI gui = new GUI();
}
public static int fak (int n) {
if (n == 0) {
return 1;
}
return n * fak(n - 1);
}
}
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GUI extends JFrame {
JButton button = new JButton("Berechnen");
JLabel label = new JLabel("Bitte geben Sie die Zahl ein: ");
JTextField textfield = new JTextField(2);
JOptionPane popup = new JOptionPane();
JPanel panel = new JPanel();
public GUI () {
setSize(300, 300);
setTitle("Fakultätsrechner");
setLayout(new FlowLayout());
setVisible(true);
panel.add(textfield);
panel.add(label);
panel.add(button);
add(panel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String input = textfield.getText();
int number = Integer.parseInt(input);
int result = Main.fak(number);
JOptionPane.showMessageDialog(null, "Die Fakultät von " + number + " ist " + result);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "Bitte geben Sie eine gültige Ganzzahl ein.");
}
}
});
}
}
Error: java.lang.ClassNotFoundException: Main
Aber wieso findet er denn die Main-Klasse nicht? Verstehe ich nicht.