Hej, próbuję robić gui w javie, z poradnika (
) ale nie wiem czemu linijka 47 (button.addActionListener(new GUI());) nie działa i wyskakuje błąd przy włączeniu:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (GUI)
at GUI.GUI.LoginGui(GUI.java:47)
at GUI.GUI.main(GUI.java:17)```
package GUI;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import date.ActionListener;
public class GUI implements ActionListener {
public static void main(String[] args)
{
System.out.println("Start");
LoginGui();
}
public static void LoginGui()
{
JPanel panel = new JPanel();
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
panel.setLayout(null);
JLabel userLabel = new JLabel("Nazwa");
userLabel.setBounds(10, 20, 80, 25);
panel.add(userLabel);
JTextField userText = new JTextField(20);
userText.setBounds(100, 20, 165, 25);
panel.add(userText);
JLabel passwordLabel = new JLabel("Hasło");
passwordLabel.setBounds(10, 50, 80, 25);
panel.add(passwordLabel);
JPasswordField passwordText = new JPasswordField(20);
passwordText.setBounds(100, 50, 165, 25);
panel.add(passwordText);
JButton button = new JButton("Login");
button.setBounds(10, 80, 80, 25);
button.addActionListener(new GUI());
panel.add(button);
JLabel success = new JLabel("");
success.setBounds(10, 110, 300, 25);
panel.add(success);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
System.out.println("ty");
}
}