📄 fund.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class Fund implements TextListener,ActionListener{//*
Frame f;
Panel p1,p2,p3;
Label lbl[];
TextField tf[] ;
Button btn[];
String lblcaption []={"本金","年利率","利息小计","利息合计"};
String ss;
public static void main(String args[]){
Fund fund = new Fund();
fund.go();
}
public void go(){
f=new Frame();
p1=new Panel();
p2=new Panel();
p3=new Panel();
lbl=new Label[4];
tf= new TextField[7];
btn=new Button[2];
f.setSize(350,200);
Font ft=new Font("Times",Font.PLAIN,24);
p1.setLayout(new GridLayout(3,3,3,3));//Panel上设立Layout
for(int i=0;i<=3;i++){//标签设立名称
lbl[i]=new Label(lblcaption[i]);
}
for(int i=0;i<=2;i++){//panel加入标签
p1.add(lbl[i]);
}
for(int i=0;i<=5;i++){//panel加入标签
tf[i]=new TextField(5);
tf[i].setText("0");
p1.add(tf[i]);
}
tf[1].addTextListener(this);//TextField事件监听
tf[4].addTextListener(this);//TextField事件监听
f.add(p1,BorderLayout.NORTH);
p2.add(lbl[3]);
tf[6]=new TextField(10);
tf[6].setText("0");
p2.add(tf[6]);
f.add(p2,BorderLayout.CENTER);
btn[0]=new Button("清除");
btn[1]=new Button("结束");
btn[0].addActionListener(this);
btn[1].addActionListener(this);
p3.add(btn[0]);
p3.add(btn[1]);
f.add(p3,BorderLayout.SOUTH);
f.setVisible(true);
}
public void textValueChanged(TextEvent te){//#TextField事件
String tf0,tf1,int1,int2,int3;
double interest1,interest2,interest3,tf0value,tf1value;
tf0=tf[0].getText();
tf1=tf[1].getText();
tf0value=Double.parseDouble(tf0);
tf1value=Double.parseDouble(tf1);
interest1=tf0value*tf1value;
int1= Double.toString(interest1);
tf[2].setText(" "+int1);
tf0=tf[3].getText();
tf1=tf[4].getText();
tf0value=Double.parseDouble(tf0);
tf1value=Double.parseDouble(tf1);
interest2=tf0value*tf1value;
int2= Double.toString(interest2);
tf[5].setText(""+int2);
interest3=interest1+interest2;
int3= Double.toString(interest3);
tf[6].setText(""+int3);
}//#
public void actionPerformed(ActionEvent ae ){
String ss;
ss=ae.getActionCommand();
if (ss.equals("清除")){
for(int i=0;i<=6;i++){
tf[i].setText("0");
}
}
else {
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -