Еве ви помош за математика

. Визуелен решавач на квадратна равенка

...:
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JApplet;
import java.awt.GridLayout;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Ravenka extends JApplet {
private JPanel jContentPane = null;
private JButton cancel = null;
private JButton ok = null;
private JLabel a = null;
private JLabel b = null;
private JLabel c = null;
private JTextField a1 = null;
private JTextField b1 = null;
private JTextField c1 = null;
public Ravenka() {
super();
}
public void init() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
}
private JPanel getJContentPane() {
if (jContentPane == null) {
c = new JLabel();
c.setText("c");
b = new JLabel();
b.setText("b");
a = new JLabel();
a.setText("a");
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(4);
gridLayout.setHgap(5);
gridLayout.setVgap(5);
gridLayout.setColumns(2);
jContentPane = new JPanel();
jContentPane.setLayout(gridLayout);
jContentPane.add(a, null);
jContentPane.add(getC1(), null);
jContentPane.add(b, null);
jContentPane.add(getB1(), null);
jContentPane.add(c, null);
jContentPane.add(getA1(), null);
jContentPane.add(getCancel(), null);
jContentPane.add(getOk(), null);
}
return jContentPane;
}
private JButton getCancel() {
if (cancel == null) {
cancel = new JButton();
cancel.setText("Cancel");
cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(-1);
}
});
}
return cancel;
}
private JButton getOk() {
if (ok == null) {
ok = new JButton();
ok.setText("Ok");
ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
float res1;
float res2;
try
{
int a=Integer.parseInt(a1.getText());
int b=Integer.parseInt(b1.getText());
int c=Integer.parseInt(c1.getText());
res1= ((float)(-b) + (float)Math.sqrt((float)(b*b) - (float)(4*a*c)))/(float)(2*a);
res2= ((float)(-b) - (float)Math.sqrt((float)(b*b) - (float)(4*a*c)))/(float)(2*a);
float res11= (float)(-b)/(float)(2*a);
float res12= (float)(Math.sqrt(((float)(b*b) - (float)(4*a*c))*(-1)))/(float)(2*a);
if(res1!=res2 && (float)(b*b) - (float)(4*a*c) >0)
JOptionPane.showMessageDialog(null, Float.toString(res1)+ " " + Float.toString(res2) );
if(res1==res2)
JOptionPane.showMessageDialog(null, Float.toString(res1) );
if ( (float)(b*b) - (float)(4*a*c) <0 )
JOptionPane.showMessageDialog(null, Float.toString(res11) + " +j" + Float.toString(res12)
+ "\n" + Float.toString(res11) + " -j" + Float.toString(res12));
}
catch(NumberFormatException ex)
{
JOptionPane.showMessageDialog(null, "Vnesi samo 1 minus" );
}
}
});
}
return ok;
}
private JTextField getA1() {
if (c1 == null) {
c1 = new JTextField();
c1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent e) {
if( !(e.getKeyChar()=='-') && (!Character.isDigit(e.getKeyChar()) ))
{
e.consume();
getToolkit().beep();
}
}
});
}
return c1;
}
private JTextField getB1() {
if (b1 == null) {
b1 = new JTextField();
b1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent e) {
if( !(e.getKeyChar()=='-') && (!Character.isDigit(e.getKeyChar()) ))
{
e.consume();
getToolkit().beep();
}
}
});
}
return b1;
}
private JTextField getC1() {
if (a1 == null) {
a1 = new JTextField();
a1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent e) {
if( !(e.getKeyChar()=='-') && (!Character.isDigit(e.getKeyChar()) ))
{
e.consume();
getToolkit().beep();
}
}
});
}
return a1;
}
}