【问题标题】:Class not abstract and does not override in abstract method [closed]类不是抽象的,也不会在抽象方法中覆盖[关闭]
【发布时间】:2014-04-25 23:12:50
【问题描述】:

大家好,我在编译我的程序时遇到了问题,有人可以帮助我吗?它说“ArrayStack 不是抽象的,不会覆盖抽象方法” 这是我的代码:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class ArrayStack extends Applet implements ActionListener {

    Button bpush,bpop,bsize,bclear,btop;
    TextField tnum,ttop,tsize;
    List list=new List();
    Label ltop,lsize;
    int top=-1,topVal;
    int stack[]=new int[10];
    int inputNum;
    int size=0;
    Font myFont,otherFont,buttonFont;
    Color myColor;

    public void init()
    {
        setLayout(null);
        setSize(530,500);
        myColor=new Color(15,125,25);
        myFont=new Font("ARIAL",Font.BOLD,14);
        otherFont=new Font("ARIAL",Font.BOLD,18);
        buttonFont=new Font("ARIAL",Font.BOLD,16);
        setBackground(Color.darkGray);
        list.add("   STACKS using an ARRAy");
        list.add("    Capacity of the Stack."+stack.length);
        list.add("+++++++++++++++++++++++++");
        list.setBounds(10,20,260,480);
        list.setFont(myFont);
        list.setBackground(Color.yellow);
        add(list);

        bpush=new Button("PUSH");
        bpush.setBounds(290,10,100,30);
        bpush.setForeground(Color.blue);
        bpush.setFont(buttonFont);
        add(bpush);

        bpop=new Button("POP");
        bpop.setBounds(400,10,100,30);
        bpop.setForeground(Color.blue);
        bpop.setFont(buttonFont);
        add(bpop);

        btop=new Button("PEEK");
        btop.setBounds(400,50,100,30);
        btop.setForeground(Color.blue);
        btop.setFont(buttonFont);
        add(btop);

        bsize=new Button("Get SIZE");
        bsize.setBounds(400,50,100,30);
        bsize.setForeground(Color.blue);
        bsize.setFont(buttonFont);
        add(bsize);

        bclear=new Button("RESET ATTACK");
        bclear.setBounds(320,450,140,30);
        bclear.setFont(buttonFont);
        add(bclear);

        tnum=new TextField("Please enter an number here...",40);
        tnum.setBounds(280,105,240,30);
        tnum.setBackground(Color.red);
        tnum.setForeground(Color.white);
        add(tnum);

        ttop=new TextField(10);
        ttop.setBounds(380,150,50,30);
        ttop.setFont(otherFont);
        ttop.setBackground(Color.blue);
        ttop.setEditable(false);
        add(ttop);

        ltop=new Label("Top Element");
        ltop.setForeground(Color.blue);
        ltop.setBounds(290,150,80,30);
        add(ltop);

        tsize=new TextField(10);
        tsize.setBounds(380,180,50,30);
        tsize.setEditable(false);
        add(tsize);
        lsize=new Label("STACK size");
        tsize.setEditable(false);
        add(lsize);

        tsize.setText(""+stack.length);
        ttop.setText("Null");
        showStatus("Loading..Initializing..");

        tnum.selectAll();
        tnum.requestFocus();

        bpush.addActionListener(this);
        bpop.addActionListener(this);
        btop.addActionListener(this);
        bsize.addActionListener(this);
        bclear.addActionListener(this);
        tnum.addActionListener(this);
    }
    public void paint(Graphics g)
    {
        showStatus("Developed by:Calixto J. Estacio Jr.(MIT-1)");
        Image stack2=getImage(getDocumentBase(),"images/stack2.png");
        g.drawImage(stack2,435,240,this);
        Image stack=getImage(getDocumentBase(),"images/stack.png");
        g.drawImage(stack2,435,240,this);
    }
    public void ActionPerformed(ActionEvent evt)
    {
        inputNum=Integer.parseInt(tnum.getText());
        if(evt.getSource()==bpush || evt.getSource()==tnum)
        {
            if(top==stack.length-1)
            {
                list.add("ERROR Exception: STACK is FULL!");
            }
            else
             {
                 top++;
                 stack[top]=inputNum;
                 topVal=stack[top];
                 list.add("PUSHED Element:"+stack[top]);
                 ttop.setText(""+topVal);
                 size=(stack.length-1)-top;
                 tsize.setText(""+size);
                }
                tnum.selectAll();
                tnum.requestFocus();
            }
            if(evt.getSource()==bpop)
            {
                if(top==-1)
                {
                    list.add("ERROR Exception:STACK is EMPTY!");
                }
                else
                {
                    topVal=stack[top];
                    list.add("POPPED Element:"+topVal);
                    top--;
                    topVal=stack[top];
                    ttop.setText(""+topVal);
                    size++;
                    tsize.setText(""+size);
                }
            }
            if(evt.getSource()==btop)
             {
                 if(top==-1)
                 {
                     list.add("ERROR Exception:Stack is EMPTY");
                    }
                    else
                    {
                        list.add("ELEMENT at the top: "+stack[top]+"at index"+top);
                    }
                }
                if(evt.getSource()==bsize)
                {
                    if(top==-1)
                    {
                        list.add("The size of the stack is: "+stack.length);
                    }
                    else
                    {
                        list.add("The size of the stack is: "+size);
                    }
                }
                if(evt.getSource()==bclear)
                {
                    list.clear();
                    list.add("   STACKS using an ARRAy");
                    list.add("    Capacity of the Stack."+stack.length);
                    list.add("+++++++++++++++++++++++++");
                    int stack[]=new int[10];
                    top=-1;
                    tsize.setText(""+stack.length);
                    ttop.setText("Null");
                    tnum.setText("");
                }
            }
        }

【问题讨论】:

  • actionPerformed 以一个小的a 开头。
  • 任何时候你重写一个方法添加@Override注解到它。

标签: java applet bluej


【解决方案1】:

您正在尝试实现ActionListener 接口,但它的actionPerformed method 以小写“a”开头。改变

public void ActionPerformed(ActionEvent evt)

public void actionPerformed(ActionEvent evt)

【讨论】:

  • 谢谢先生!这是我第一次在网上问。非常感谢先生!你救了我的命!有用!现在我可以去睡觉了哈哈。
猜你喜欢
  • 2014-06-20
  • 2021-09-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多