【问题标题】:getActionCommand is undefinedgetActionCommand 未定义
【发布时间】:2018-05-07 18:43:03
【问题描述】:

我一直在使用我的教科书来构建 GUI,但有一件事一直困扰着我。当我尝试使用 removeAll 方法制作一个清除按钮时,它根本不起作用。我遇到的问题是 GetActionCommand() is undefined 。

import acm.graphics.*;
import acm.program.*;
import java.awt.*;
import java.awt.event.*;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.JLabel;
import javax.swing.JSlider;

import acm.program.GraphicsProgram;
import javafx.event.ActionEvent;

public class GUI_Program extends GraphicsProgram{

public void init() {
    setBackground(Color.GRAY);
    add(Cleared, WEST);
    addActionListeners();
    sizeSlider = new JSlider(MIN_SIZE, MAX_SIZE, INITIAL_SIZE);
    add(new JLabel(" small"), WEST);
    add(sizeSlider, WEST);
    add(new JLabel("Large "), WEST);
    ColorBox();

    add(colorBox, WEST);

    addMouseListeners();

}
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Clear")) {
        removeAll();
    }
}

【问题讨论】:

    标签: java swing removeall actionevent


    【解决方案1】:

    问题出在这一行:

    import javafx.event.ActionEvent;

    ActionEvent 类不止一个,这是错误的。删除此行应该可以修复错误。 (正确的ActionEvent 将通过代码中已有的import java.awt.event.*; 行导入。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-21
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多