实训要求:
代码:
EquationException类:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class EquationException extends RuntimeException {
public static final int NONE_EQUATION = 1;
public static final int NO_REALROOT = 2;
private int errorCode;
public EquationException(String msg, int errorCode) {
super(msg);
this.errorCode = errorCode;
}
public int getErrorCode() {
return errorCode;
}
}
public class EquationFrame extends JFrame implements ActionListener {
SquareEquation equation;
JTextField textA, textB, textC;
JTextArea showRoots;
JButton controlButton;
public EquationFrame() {
equation = new SquareEquation();
textA = new JTextField(8);
textB = new JTextField(8);
textC = new JTextField(8);
controlButton = new JButton("确定");
JPanel pNorth = new JPanel();
pNorth.add(new JLabel("二次项系数:"));
pNorth

本文是关于Java编程的实训内容,重点在于编写一个窗体程序,该程序能够计算一元二次方程的解。通过EquationException类处理计算中可能出现的异常,实现了用户友好的交互体验。
最低0.47元/天 解锁文章
5006

被折叠的 条评论
为什么被折叠?



