2014-03-19 148 views
-1

嘿家伙我在编译我的程序时遇到麻烦,有人可以帮我吗?它说,“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(""); 
       } 
      } 
     } 
+0

'actionPerformed'用小'了'开始。 – ajb

+1

任何时候你重写一个方法的时候,都会给它添加'@ Override'注解。 –

回答

3

您正试图实现ActionListener接口,但其开始actionPerformed method用小写的“a”。更改

public void ActionPerformed(ActionEvent evt) 

public void actionPerformed(ActionEvent evt) 
+0

谢谢你先生!这是我第一次在线询问。非常感谢你先生!你救了我的命!有用!现在我可以去睡觉了哈哈。 – Calixto

相关问题