java小程序修改

我想做一个数的阶乘如何修改?classjiechengextendsFrameimplementsTextListener,WindowListener{staticTe... 我想做一个数的阶乘如何修改?
class jiecheng extends Frame implements TextListener ,WindowListener
{
static TexEvent frm=new TexEvent();
static TextField txt1,txt2 ;
static Label lable1;
void fangfa9()
{ frm.setTitle("一个数的阶乘");
frm.setBounds(250,250,200,200);
frm.setLayout(new FlowLayout());
txt1=new TextField(20);
txt2=new TextField(20);
txt1.addTextListener(frm);
lable1=new Label("请输入一个整数");
frm.add(lable1);
txt2.setEditable(false);

frm.add(txt1);
frm.add(txt2);

frm.setVisible(true);
frm.addWindowListener(this);
}
public void textValueChanged(TextEvent e)
{
Double a;
Double b=1.0;
a=Double.parseDouble(txt1.getText());
for(double i =1.0;i<=a;i++)
{
b=b*i;
}
txt2.setText(String.valueOf(b));
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub

}
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
frm.dispose();
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub

}
}
展开
 我来答
匿名用户
2013-12-21
展开全部
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();
    }
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式