import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Main implements ActionListener { public static void main(String[] args) { JFrame f = new JFrame(); JPanel p = new JPanel(); Label l = new Label("Sam"); Button b = new Button("Click me"); Label l2 = new Label(); l.setBounds(3,5,4000,5000); l.setForeground(Color.BLUE); b.setLocation(5,5); b.setSize(1,1); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(500,600); f.setResizable(false); p.add(l); p.add(b); p.setBackground(Color.red); f.add(p); b.addActionListener(this); public void actionPerformed(ActionEvent e){ String str = e.getActionCommand(); if(str.equals("Click me")) System.out.println("GM"); } }}這就是為什么 Intellij 在 actionPerformed 方法中顯示錯誤的原因。他們在 ActionEvent e 的聲明中顯示錯誤。錯誤:請幫助我,我是初學者。這也是正確的: b.addActionListener(this); ?
actionPerformed 方法中的錯誤
幕布斯6054654
2021-07-13 21:09:57