📄 applet1.java
字号:
package whileexample;import java.awt.*;import java.awt.event.*;import java.applet.*;import com.borland.jbcl.layout.*;public class Applet1 extends Applet { double x,y; double result[]; int mul ; int i,j ; boolean isStandalone = false; XYLayout xYLayout1 = new XYLayout(); TextField text1 = new TextField(); Label label1 = new Label(); Button button1 = new Button(); /**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 Applet1() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { this.setLayout(xYLayout1); label1.setText("计算exp(x) x="); button1.setFont(new java.awt.Font("Dialog", 0, 16)); button1.setLabel("确定"); button1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { button1_mouseClicked(e); } }); text1.setFont(new java.awt.Font("Dialog", 0, 16)); this.add(text1, new XYConstraints(148, 50, 72, 26)); this.add(label1, new XYConstraints(54, 52, 81, 21)); this.add(button1, new XYConstraints(40, 105, 181, 24)); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } public void paint(Graphics g){ g.drawString("结果是:"+String.valueOf(result[i]),100,200); } void button1_mouseClicked(MouseEvent e) { i = 1; result = new double[1000]; result[0] = 1; String str1 = text1.getText() ; try{ x = Double.parseDouble(str1); result[1] = 1+x; do{ i++; mul=1; y=1; for(j=1;j<=i;j++){ mul = mul*j; y = y*x; } result[i] = result[i-1] + y/mul; } while(Math.abs(result[i]-result[i-1])>0.00001); repaint(); } catch(Exception ex){ ex.printStackTrace() ; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -