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
}
} 展开
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
}
} 展开
1个回答
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();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询