jbuilder 100例 java源码学习,非常不错,有需要朋友下来

源代码在线查看: ifexample.java~22~

软件大小: 6566 K
上传用户: xiaoexiao
关键词: jbuilder java 100 源码
下载地址: 免注册下载 普通下载 VIP

相关代码

				package untitled2;								import java.awt.*;				import java.awt.event.*;				import java.applet.*;				import com.borland.jbcl.layout.*;								public class ifexample extends Applet {				  double result;				  boolean isStandalone = false;				  TextField paratext1 = new TextField();				  TextField paratext2 = new TextField();				  TextField paratext3 = new TextField();				  Label label1 = new Label();				  Label label2 = new Label();				  Label label3 = new Label();				  Button button1 = new Button();				  TextField resulttext1 = new TextField();				  XYLayout xYLayout1 = new XYLayout();				  TextField resulttext2 = new TextField();				  Label label4 = new Label();				  Label label5 = new Label();				  /**Get a parameter value*/				  public String getParameter(String key, String def) {				    return isStandalone ? System.getProperty(key, def) :				      (getParameter(key) != null ? getParameter(key) : def);				  }								  /**Construct the applet*/				  public ifexample() {				  }				  /**Initialize the applet*/				  public void init() {				    try {				      jbInit();				    }				    catch(Exception e) {				      e.printStackTrace();				    }				  }				  /**Component initialization*/				  private void jbInit() throws Exception {				    paratext1.setFont(new java.awt.Font("Dialog", 0, 16));				    paratext1.setText("0");				    paratext2.setFont(new java.awt.Font("Dialog", 0, 16));				    paratext2.setText("0");				    paratext3.setFont(new java.awt.Font("Dialog", 0, 16));				    paratext3.setText("0");				    label1.setFont(new java.awt.Font("Dialog", 0, 16));				    label1.setText("a");				    label2.setFont(new java.awt.Font("Dialog", 0, 16));				    label2.setText("b");				    label3.setFont(new java.awt.Font("Dialog", 0, 16));				    label3.setText("c");				    button1.setLabel("计算");				    button1.addActionListener(new java.awt.event.ActionListener() {				      public void actionPerformed(ActionEvent e) {				        button1_actionPerformed(e);				      }				    });				    resulttext1.setEditable(false);				    resulttext1.setFont(new java.awt.Font("Dialog", 0, 16));				    this.setLayout(xYLayout1);				    resulttext2.setEditable(false);				    resulttext2.setFont(new java.awt.Font("Dialog", 0, 16));				    label4.setFont(new java.awt.Font("Dialog", 0, 16));				    label4.setText("x1=");				    label5.setFont(new java.awt.Font("Dialog", 0, 16));				    label5.setText("x2=");				    this.add(paratext3,    new XYConstraints(120, 100, 70, -1));				    this.add(button1,    new XYConstraints(120, 140, -1, -1));				    this.add(paratext2,     new XYConstraints(120, 70, 70, -1));				    this.add(paratext1,     new XYConstraints(120, 40, 70, -1));				    this.add(label3,   new XYConstraints(100, 100, -1, -1));				    this.add(resulttext1,  new XYConstraints(120, 178, 120, -1));				    this.add(resulttext2,  new XYConstraints(120, 218, 120, -1));				    this.add(label5,    new XYConstraints(70, 218, 46, 27));				    this.add(label4,    new XYConstraints(70, 178, 46, 28));				    this.add(label1,   new XYConstraints(100, 40, -1, -1));				    this.add(label2,   new XYConstraints(100, 70, -1, -1));				  }				  /**Get Applet information*/				  public String getAppletInfo() {				    return "Applet Information";				  }				  /**Get parameter info*/				  public String[][] getParameterInfo() {				    return null;				  }								  void button1_actionPerformed(ActionEvent e) {				      double a1,b1,c1;				      double sqrt;				      double x1,x2;				      try{				         a1 = Double.parseDouble(paratext1.getText());				         b1 = Double.parseDouble(paratext2.getText());				         c1 = Double.parseDouble(paratext3.getText());				         if ((a1 == 0)&&(b1 != 0)){				             x1 = c1/b1;				             resulttext1.setText(String.valueOf(x1));				         }				         if (a1 != 0){				            if ((b1*b1-4*a1*c1)>=0){				              sqrt = getsqrt(a1,b1,c1);				               x1 = ((-1)*b1+sqrt)/(2*a1);				               x2 = ((-1)*b1-sqrt)/(2*a1);				              resulttext1.setText(String.valueOf(x1));				              resulttext2.setText(String.valueOf(x2));				            }				        if ((b1*b1-4*a1*c1)				               sqrt = getsqrt(a1,b1,c1);				               resulttext1.setText(String.valueOf((-1)*b1/(2*a1))+"+"+String.valueOf(sqrt/(2*a1),4)+"i");				               resulttext2.setText(String.valueOf((-1)*b1/(2*a1))+"-"+String.valueOf(sqrt/(2*a1),4)+"i");				            }				          }				      }catch(Exception ex){}				  }				  public double getsqrt(double x,double y,double z){				       result = Math.sqrt(Math.abs(y*y-4*x*z));				       return result;				   }				}			

相关资源