类不是抽象的,并且不会覆盖ActionListener

时间:2017-05-04 19:35:15

标签: java user-interface actionlistener

我已经尝试了一切..我尝试过添加覆盖,确保我有自己的actionPerformed方法..我被卡住了。它一直给我错误,“类不是抽象的,并且不会在ActionListener中覆盖抽象方法actionPerformed(ActionEvent)。”请帮忙:(

package teststudentdatabase;

import java.io.*;
import javax.swing.*;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import javafx.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

class GUI extends JFrame implements ActionListener {
    //initializing and defining variables
    private JFrame frame = new JFrame("Grid Layout");
    private JButton process = new JButton("Process Request");
    private JTextField identificationBox = new JTextField(30);
    private JTextField nameBox = new JTextField(30);
    private JTextField majorBox = new JTextField(30);
    private JLabel identificationLabel = new JLabel("Id:");
    private JLabel nameLabel = new JLabel("Name:");
    private JLabel majorLabel = new JLabel("Major:");
    private JLabel chooseLabel = new JLabel("Choose Selection:");
    private JLabel blank = new JLabel("");   
    private String[] choices = {"Insert", "Delete", "Find", "Update"};
    private JComboBox choiceList = new JComboBox(choices);

    //constructor
    public GUI(){
        setLayout(new GridLayout(5, 2, 20, 10));
        setTitle("Project 4");
        setSize(500,300);
        setLocation(600,200); 
        add(identificationLabel);
        add(identificationBox);
        add(nameLabel);
        add(nameBox);
        add(majorLabel);
        add(majorBox);
        add(chooseLabel);
        add(choiceList);
        choiceList.setSelectedIndex(0);
        //choiceList.addActionListener(this);
        add(process);
        process.addActionListener(this);
    }

    //actionlistener method

    @Override
    public void actionPerformed(ActionEvent event){
        try{
            String text = process.getText();
            JComboBox cb = (JComboBox)event.getSource();
            String message = (String)cb.getSelectedItem();
            if (process == event.getSource() && message == "Insert"){
                JOptionPane.showMessageDialog(null,text);
            }
        }

        catch(Exception e){
            JOptionPane.showMessageDialog(null, "Nopeee");
        }


    }
}

0 个答案:

没有答案