import java.awt.*;
import java.awt.event.*;
public class QuadraticSolver extends Frame implements ActionListener, WindowListener
{
private TextField tfX2;
private TextField tfX;
private TextField tfNum;
private TextField tfVal1;
private TextField tfVal2;
private TextField tfRoots;
private Label lblX2;
private Label lblX;
private Label lblNum;
private Label lblVal1;
private Label lblVal2;
private Label lblRoots;
private Button btnCheckRoots;
private Button btnCalc;
private Button btnClear;
double a = 0, b = 0, c = 0;
double Val1 = 0, Val2 = 0, Discriminant = 0;
String StrVal1, StrVal2;
public QuadraticSolver()
{
Panel panelX2Comp = new Panel(new FlowLayout());
{
lblX2 = new Label("Enter Co-Efficient Of X^2:");
panelX2Comp.add (lblX2);
tfX2 = new TextField("", 20);
tfX2.setEditable(true);
panelX2Comp.add(tfX2);
}
Panel panelXComp = new Panel(new FlowLayout());
{
lblX = new Label("Enter Co-Efficient Of X:");
panelXComp.add(lblX);
tfX = new TextField("", 20);
tfX.setEditable(true);
panelXComp.add(tfX);
}
Panel panelNumComp = new Panel(new FlowLayout());
{
lblNum = new Label("Enter Number:");
panelNumComp.add(lblNum);
tfNum = new TextField("", 20);
tfNum.setEditable(true);
panelNumComp.add(tfNum);
}
Panel panelButtons = new Panel(new FlowLayout());
{
btnCalc = new Button("Calculate");
btnCalc.setEnabled(false);
panelButtons.add(btnCalc);
{
btnCalc.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
a = Double.parseDouble(tfX2.getText());
b = Double.parseDouble(tfX.getText());
c = Double.parseDouble(tfNum.getText());
Val1 = (-b + Math.sqrt(Discriminant)) / (2 * a);
Val2 = (-b - Math.sqrt(Discriminant)) / (2 * a);
StrVal1 = String.valueOf(Val1);
StrVal2 = String.valueOf(Val2);
tfVal1.setText(StrVal1);
tfVal2.setText(StrVal2);
tfX2.setText("");
tfX.setText("");
tfNum.setText("");
btnCalc.setEnabled(false);
}
}
);
}
btnCheckRoots = new Button("Nature Of Roots");
panelButtons.add(btnCheckRoots);
{
btnCheckRoots.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
a = Double.parseDouble(tfX2.getText());
b = Double.parseDouble(tfX.getText());
c = Double.parseDouble(tfNum.getText());
Discriminant = (b*b) - (4*(a*c));
if (Discriminant == 0)
{
tfRoots.setText("Equal");
btnCalc.setEnabled(true);
}
else if (Discriminant < 0)
{
tfRoots.setText("Imaginary");
}
else
{
tfRoots.setText("Real, Distinct");
btnCalc.setEnabled(true);
}
}
}
);
}
btnClear = new Button("Clear");
panelButtons.add(btnClear);
{
btnClear.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
a = 0; b = 0; c = 0;
Val1 = 0; Val2 = 0; Discriminant = 0;
tfX2.setText("");
tfX.setText("");
tfNum.setText("");
tfVal1.setText("");
tfVal2.setText("");
tfRoots.setText("");
}
}
);
}
}
Panel panelRoots = new Panel(new FlowLayout());
{
lblRoots = new Label ("Nature Of Roots:");
panelRoots.add(lblRoots);
tfRoots = new TextField("", 20);
tfRoots.setEditable(false);
panelRoots.add(tfRoots);
}
Panel panelValues = new Panel(new FlowLayout());
{
lblVal1 = new Label("First Value:");
panelValues.add(lblVal1);
tfVal1 = new TextField("", 10);
tfVal1.setEditable(false);
panelValues.add(tfVal1);
lblVal2 = new Label("Second Value:");
panelValues.add(lblVal2);
tfVal2 = new TextField("", 10);
tfVal2.setEditable(false);
panelValues.add(tfVal2);
}
setLayout(new FlowLayout()); // "this" Frame sets to BorderLayout
add(panelX2Comp);
add(panelXComp);
add(panelNumComp);
add(panelButtons);
add(panelRoots);
add(panelValues);
setTitle("Matrix Multiplier"); // "this" Frame sets title
setSize(400, 200); // "this" Frame sets initial size
setVisible(true);
addWindowListener(this);
}
@Override
public void windowClosing(WindowEvent e)
{
System.exit(0); // Terminate the program
}
@Override
public void windowOpened(WindowEvent e) { }
@Override
public void windowClosed(WindowEvent e) { }
@Override
public void windowIconified(WindowEvent e) { }
@Override
public void windowDeiconified(WindowEvent e) { }
@Override
public void windowActivated(WindowEvent e) { }
@Override
public void windowDeactivated(WindowEvent e) { }
public static void main(String args[])
{
new QuadraticSolver();
}
}
这就是我的代码。它给我一个错误说“QuadraticSolver.java:4:错误:QuadraticSolver
不abstract
,不重写抽象方法actionPerformed(ActionEvent)
在ActionListener
public class QuadraticSolver extends Frame implements ActionListener, WindowListener
”
我不知道该怎么做。我尝试在所有ActionListener事件之前添加@Override,但仍然无法正常工作。
既然QuadraticSolver
实施ActionListener
,就应该实施actionPerformed
。
您在匿名类中实现了该方法。
为了解决这个问题,无论是添加的实现
actionPerformed
来QuadraticSolver
或不要求QuadraticSolver
实现该接口。
问题内容: 因此,我一直在为编程类编写抽象作业,但遇到了问题。我现在的目标是能够使用抽象,然后能够使用矩形和椭圆形绘制一个简单的城市,例如矩形建筑物或灯柱上的椭圆形灯。 我在编译时收到的错误是:MyTestApp.Rectangle不是抽象的,并且不会覆盖MyTestApp.Shape中的抽象方法drawEllipse(java.awt.Graphics)。该错误显示在类Shape下方的“矩形扩展
请帮帮忙!!我一直在到处寻找,但没有得到答案 错误:MainApplication不是抽象的,并且不覆盖抽象方法 环境 android/build.gradle系统 App/build.gradle 我的主应用程序 错误: 任务:app:compileDebugJavaWithJavac C:\Users\user\Downloads\Scripts\kantongin mobile\trader
我是android开发的新手,在我的应用程序中,我使用房间数据库来进入数据库。
//AListener不是抽象的,也不会覆盖抽象方法actionPerform(ActionEvener)中的ActionListener????
我尝试了所有的可能性,但错误仍然出现: 选择java:4:错误:Select不是抽象的,并且不会覆盖ActionListener中的抽象方法actionPerformed(ActionEvent)
如何解决此错误,我不想删除。请任何人在不删除`implements actionlistener的情况下更正此错误。