0
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javafx.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class View extends JFrame{
JTextField tField = new JTextField(10);
JButton sortButton = new JButton("Sort");
JButton shuffleButton = new JButton("Shuffle");
JButton reverseButton = new JButton("Reverse");
JTextArea tArea = new JTextArea();
JLabel label = new JLabel("Enter a number: ");
JPanel upperPanel = new JPanel();
JPanel buttonPanel = new JPanel();
public View(){
setTitle("Exercise 22.2");
setSize(500,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new BorderLayout());
sortButton.addActionListener(new Listener());
upperPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
upperPanel.add(label);
upperPanel.add(tField);
buttonPanel.add(sortButton);
buttonPanel.add(shuffleButton);
buttonPanel.add(reverseButton);
add(upperPanel, BorderLayout.NORTH);
add(tArea, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
}
/*Getting error here!*/
public class Listener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello");
}
}
}
我想創建一個實現ActionListener的類,以便我可以將類註冊到我的按鈕。View.Listener不是抽象的,並且不會覆蓋ActionListener中的抽象方法actionPerformed(ActionEvent)
我越來越: View.Listener不是抽象和ActionListener的
我試着實現爲匿名類沒有重載抽象方法的actionPerformed(動作事件),並得到同樣的錯誤。我想不明白。