定义一个 EquationFrame类,具体代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
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.add(textA);
pNorth.add(new JLabel("一次项系数:"));
pNorth.add(textB);
pNorth.add(new JLabel("常数项系数:"));
pNorth.add(textC);
pNorth.add(controlButton);
controlButton.addActionListener(this);
getContentPane().add(pNorth,BorderLayout.NORTH);
showRoots=new JTextArea();
JScrollPane scrollPane=new JScrollPane(showRoots);
getContentPane().add(scrollPane,BorderLayout.CENTER);
setSize(630,160);
Dimension scnSize=Toolkit.getDefaultToolkit().g