gpt4 book ai didi

java - 类不是抽象的,并且不会在抽象方法中重写

转载 作者:行者123 更新时间:2023-12-01 18:34:46 24 4
gpt4 key购买 nike

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

最佳答案

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

public void ActionPerformed(ActionEvent evt)

public void actionPerformed(ActionEvent evt)

关于java - 类不是抽象的,并且不会在抽象方法中重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22510424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com