class jiecheng extends Frame implements TextListener ,WindowListener{ TextField txt1,txt2 ; Label lable1; jiecheng(){ super("数阶乘"); this.setBounds(250,250,200,200); this.setLayout(new FlowLayout()); txt1=new TextField(20); txt2=new TextField(20); txt1.addTextListener(this); lable1=new Label("请输入整数"); this.add(lable1); txt2.setEditable(false); this.add(txt1); this.add(txt2); this.setVisible(true); this.addWindowListener(this); } public void textValueChanged(TextEvent e){ Double a=-1D; Double b=1.0; try{ a=Double.parseDouble(txt1.getText()); for(double i =1.0;i<=a;i++){ b=b*i; } txt2.setText(String.valueOf(b)); }catch(Exception ex){ ex.printStackTrace(); } } public void windowActivated(WindowEvent arg0) { } public void windowClosed(WindowEvent arg0) { } public void windowClosing(WindowEvent arg0) { this.dispose(); } public void windowDeactivated(WindowEvent arg0) { } public void windowDeiconified(WindowEvent arg0) { } public void windowIconified(WindowEvent arg0) { } public void windowOpened(WindowEvent arg0) { } public static void main(String args[]){ new jiecheng(); } }