2016-10-29 3 views
0

이 코드에서 누락 된 부분을 파악할 수 없습니다. "ButtonListiner는 추상이 아니며 ActionListener에서 추상 메소드 actionPerformed (ActionEvent)를 대체하지 않습니다." 하지만 난 actionPerformed 사용하고 클래스 및 메서드 위에 @Override 시도하고 여전히 작동하지 않습니다. SubmitButtonListener 클래스와 ExitButtonListener 클래스에서 모두 같습니다.청취자는 추상 메소드가 아니며 추상 메소드를 재정의하지 않습니다. JAVA

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 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(); 
} 

} 

감사합니다> 여기> 여기

/** 
* 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); 
     } 
    } 
} 

을 시작합니다.

+0

달성하고자하는 것은 무엇입니까? –

답변

0

정확하게 java.awt.event.ActionEvent을 가져 왔는지 확인해야합니다. 에서 잘못된 유형의 ActionEvent을 잘못 가져 오지 않았는지 확인하십시오.

이 문제는 일반적으로 IDE (Eclipse/IntellliJ/etc ..)를 사용하고 우연히 다른 원하지 않는 유형으로 자동 가져 오기 할 때 발생합니다.

+0

고마워. Idk 왜 자동으로 다른 청취자를 넣어. –

관련 문제