gpt4 book ai didi

java - Action 监听器错误

转载 作者:行者123 更新时间:2023-12-01 06:44:11 24 4
gpt4 key购买 nike

当我实现 ActionListener 时,我不断收到错误消息。我真的不明白如何解决它。我执行了 actionPerformed (ActionEvent ev) {} 并放置登录按钮以使用 lg.addActionListener(this); 调用它;

import java.awt.*;
import javax.swing.*;
import java.awt.Event.*;
import java.applet.Applet;

public class LoginScreen extends JApplet implements ActionListener {
JTextField un;
JPasswordField pw;
JButton lg;
JLabel user,pass;

public LoginScreen () {
un = new JTextField ();
pw = new JPasswordField ();
lg = new JButton ("login");
user = new JLabel ("username");
pass = new JLabel ("password");

lg.addActionListener(this);

this.setLayout(null);

user.setBounds(10, 10, 120, 20);
pass.setBounds(10, 30, 120, 20);
un.setBounds(140, 10, 200, 20);
pw.setBounds(140, 30, 200, 20);

lg.setBounds(140, 55, 100, 20);

this.add(user);
this.add(pass);
this.add(un);
this.add(pw);
this.add(lg);

this.setSize(500, 300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ev) {

}
}

最佳答案

import java.awt.Event.*; 更改为 import java.awt.event.*;

Java 区分大小写。

同时更改import java.applet.Applet; -> import javax.swing.JApplet;

关于java - Action 监听器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20875648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com