我正在尝试创建一个按钮,一旦按下它就会擦除旧屏幕并绘制新的东西。我计划画一个房间,然后在门上加一个按钮。当按下门上的按钮时,它应该擦除旧屏幕并在新房间中绘制。
为什么我会收到此错误:
Test is not abstract and does not override abstract method
actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
相关代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.JComponent.*;
public class Test extends JFrame implements ActionListener{
private JLabel msg;
private final String ButtonText = "Room";
public void init()
{
Container contentHolder = getContentPane();
contentHolder.setLayout(new BorderLayout(18,18));
msg = new JLabel("");
contentHolder.add(msg, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
JButton myButton = new JButton(ButtonText);
myButton.addActionListener(this);
buttonPanel.add(myButton);
contentHolder.add(buttonPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent evt, Graphics g)
{
String command = evt.getActionCommand();
if(ButtonText.equals(command))
{
Dimension d = getSize();
g.setColor(Color.WHITE);
g.fillRect(0, 0, d.width, d.height);
house.drawRoom(g);
}
}
}
class house extends Test
{
public static void drawRoom(Graphics g)
{
Expo.drawCircle(g,100,100,25);
}
}