Я пытаюсь скомпилировать свой код, но я продолжаю получать компиляционную ошибку, которую я делаю не знаю, как исправить. Ошибка возникает в строкеТип 'xxx' должен реализовать унаследованный абстрактный метод java.awt.event.ActionListener.actionPerformed (java.awt.event.ActionEvent)
public class MovingSignPanel extends JPanel implements ActionListener {
и ошибка
The type MovingSignPanel must implement the inherited abstract method java.awt.event.ActionListener.actionPerformed(java.awt.event.ActionEvent)
, если один из вас прекрасные люди могли бы помочь мне, что это было бы весьма признателен.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MovingSignPanel extends JPanel implements ActionListener {
JButton move = new JButton("Move");
JButton quit = new JButton("Quit");//create buttons
private int press;
private int x;
private int y;
private String time;
public void CityPanel() {
press = 0;
this.add(move);
move.addActionListener(this);
this.add(quit);
quit.addActionListener(this);
x = 5;
y = 175;//will be starting place for sun
time = "8 AM";//will be starting time
}
public void moveSun(ActionEvent e) {
if (e.getSource() == move) {
{
press = 0;
}
x = 5;
y = 175;
time = "8 AM";
super.repaint();
} else if (press == 1) {
x = 100;
y = 75;
time = "10 AM";
super.repaint();
} else if (press == 2) {
x = 250;
y = 80;
time = "12 PM";
super.repaint();
} else if (press == 3) {
x = 350;
y = 140;
time = "2 pm";
super.repaint();
} else if (press == 4) {
x = 415;
y = 200;
time = "4 PM";
super.repaint();
} else if (press == 5) {
x = 465;
y = 230;
time = "6 PM";
super.repaint();
} else if (press == 6) {
x = 500;
y = 260;
time = "8 PM";
super.repaint();
}
press += 1;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.black);//color for buildings
g.drawRect(150, 275, 50, 80);
g.drawRect(200, 250, 50, 100);//draw buildings
g.drawRect(300, 300, 30, 60);
g.drawRect(100, 275, 40, 40);
g.drawLine(0, 350, 500, 350);
g.drawString(time, x, y + 75);//gives time
g.setColor(Color.yellow);//color for sun
g.fillOval(x, y, 50, 50);//draws sun
}
}
Ошибка не требует пояснений: вам нужно реализовать метод actionPerformed (java.awt.event.ActionEvent) ' – Raptor
' MovingSignPanel' реализует интерфейс 'ActionListener'. Вам нужно объявить и определить метод 'void actionPerformed (ActionEvent)' в 'class MovingSignPanel' – anonymous
Вам нужно знать больше о Java OOP. – Ericton