侦听器不是抽象的,不会覆盖抽象方法JAVA
Listener is not abstract and does not override abstract method JAVA
我不知道我在这段代码中遗漏了什么。它一直在说 "ButtonListiner is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener." 但我正在使用 actionPerformed 并且我已经在 class 和方法上方尝试了 @Override 但它仍然无法正常工作。我的 SubmitButtonListener class 和 ExitButtonListener class.
都是一样的
package customerinserterproblem_alliebeckman;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javafx.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class CustomerInserterProblem_AllieBeckman extends JFrame{
CustomerInfoPanel customerInfoPanel; // Panel for customer information
JPanel buttonPanel; // Panel for buttons
/**
* Constructor
*/
public CustomerInserterProblem_AllieBeckman()
{
// Set the window title
setTitle("Add Customer");
// Specify an action for the close button
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a CustomerInfoPanelObject
customerInfoPanel = new CustomerInfoPanel();
// Build the buttonPanel object
buildButtonPanel();
// Add the panels to the content pane
add(customerInfoPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
// Pack and display the window
pack();
setVisible(true);
}
/**
* buildButtonPanel method
*/
private void buildButtonPanel()
{
// Create a panel for the buttons
buttonPanel = new JPanel();
// Create a submit button and add an action listener
JButton submitButton = new JButton("Submit");
submitButton.addActionListener(new SubmitButtonListener());
// Create an Exit button
JButton exitButton = new JButton("Exit");
exitButton.addActionListener(new ExitButtonListener());
// Add the buttons to the panel.
buttonPanel.add(submitButton);
buttonPanel.add(exitButton);
}
我的问题从这里开始 >
/**
* Private inner class that handles submit button events
*/
private class SubmitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e){
try
{
// Get the customer information from the text fields
String custNum = customerInfoPanel.getCustNum();
String name = customerInfoPanel.getName();
String address = customerInfoPanel.getAddress();
String city = customerInfoPanel.getCity();
String state = customerInfoPanel.getState();
String zip = customerInfoPanel.getZip();
// Create a CustomerTableManager object
CustomerTableManager ctManager = new CustomerTableManager();
// Insert the record
ctManager.insert(custNum, name, address, city, state, zip);
// clear the text fields
customerInfoPanel.clear();
// Let the user know the record was added.
JOptionPane.showMessageDialog(null, "Record Added");
}
catch (SQLException ex){
ex.printStackTrace();
System.exit(0);
}
}
}
这里 >
/**
* Private inner class that handles Exit Button events
*/
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e){
// Exit the app
System.exit(0);
}
}
/**
* main method
*/
public static void main(String[] args){
new CustomerInserterProblem_AllieBeckman();
}
}
感谢您的提前帮助。
您需要正确检查您是否已正确导入 java.awt.event.ActionEvent
。
确保您没有错误地从 some other package
导入错误类型的 ActionEvent
。
当您使用 IDE(如 Eclipse/IntellliJ/etc..)并意外自动导入到不同的不需要的类型时,通常会出现此问题。
我不知道我在这段代码中遗漏了什么。它一直在说 "ButtonListiner is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener." 但我正在使用 actionPerformed 并且我已经在 class 和方法上方尝试了 @Override 但它仍然无法正常工作。我的 SubmitButtonListener class 和 ExitButtonListener class.
都是一样的package customerinserterproblem_alliebeckman;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javafx.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class CustomerInserterProblem_AllieBeckman extends JFrame{
CustomerInfoPanel customerInfoPanel; // Panel for customer information
JPanel buttonPanel; // Panel for buttons
/**
* Constructor
*/
public CustomerInserterProblem_AllieBeckman()
{
// Set the window title
setTitle("Add Customer");
// Specify an action for the close button
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a CustomerInfoPanelObject
customerInfoPanel = new CustomerInfoPanel();
// Build the buttonPanel object
buildButtonPanel();
// Add the panels to the content pane
add(customerInfoPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
// Pack and display the window
pack();
setVisible(true);
}
/**
* buildButtonPanel method
*/
private void buildButtonPanel()
{
// Create a panel for the buttons
buttonPanel = new JPanel();
// Create a submit button and add an action listener
JButton submitButton = new JButton("Submit");
submitButton.addActionListener(new SubmitButtonListener());
// Create an Exit button
JButton exitButton = new JButton("Exit");
exitButton.addActionListener(new ExitButtonListener());
// Add the buttons to the panel.
buttonPanel.add(submitButton);
buttonPanel.add(exitButton);
}
我的问题从这里开始 >
/**
* Private inner class that handles submit button events
*/
private class SubmitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e){
try
{
// Get the customer information from the text fields
String custNum = customerInfoPanel.getCustNum();
String name = customerInfoPanel.getName();
String address = customerInfoPanel.getAddress();
String city = customerInfoPanel.getCity();
String state = customerInfoPanel.getState();
String zip = customerInfoPanel.getZip();
// Create a CustomerTableManager object
CustomerTableManager ctManager = new CustomerTableManager();
// Insert the record
ctManager.insert(custNum, name, address, city, state, zip);
// clear the text fields
customerInfoPanel.clear();
// Let the user know the record was added.
JOptionPane.showMessageDialog(null, "Record Added");
}
catch (SQLException ex){
ex.printStackTrace();
System.exit(0);
}
}
}
这里 >
/**
* Private inner class that handles Exit Button events
*/
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e){
// Exit the app
System.exit(0);
}
}
/**
* main method
*/
public static void main(String[] args){
new CustomerInserterProblem_AllieBeckman();
}
}
感谢您的提前帮助。
您需要正确检查您是否已正确导入 java.awt.event.ActionEvent
。
确保您没有错误地从 some other package
导入错误类型的 ActionEvent
。
当您使用 IDE(如 Eclipse/IntellliJ/etc..)并意外自动导入到不同的不需要的类型时,通常会出现此问题。