문제

Hey guys Im having a trouble with compiling my program, can someone help me? It says that "ArrayStack is not abstract and does not override abstract method" Here is my code:

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("");
                }
            }
        }
도움이 되었습니까?

해결책

You are attempting to implement the ActionListener interface, but its actionPerformed method starts with a lowercase "a". Change

public void ActionPerformed(ActionEvent evt)

to

public void actionPerformed(ActionEvent evt)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top