计算器小程序代码求修改帮助~
import java.awt.event.*;import java.applet.Applet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class dzy extends Applet implements ActionListener{
private JPanel jp = new JPanel();
private JLabel[] jlArray = { new JLabel("有理数的第一个操作:"), new JLabel("有理数的第一个操作:"),
new JLabel("输出:"), new JLabel("/"),new JLabel("/"),new JLabel("/")};
JButton[] jbArray = { new JButton("+"), new JButton("-"),new JButton("*"),new JButton("+"),new JButton("清空") };
JTextField[] jtxtName ={ new JTextField(),new JTextField(),new JTextField(),new JTextField(),new JTextField(),new JTextField()};
public dzy(){
jp.setLayout(null);
for (int i=0;i<5; i++) {
jp.add(jbArray[i]);
jbArray[i].setBounds(50 + i+100, 130, 80, 26);
jbArray[i].addActionListener(this);}
for (int a=0;a<5; a++) {
jp.add(jtxtName[a]);
jtxtName[a].setBounds(80, 20+a, 180, 30);
jtxtName[a].addActionListener(this);}
for (int b=0;b<5; b++) {
jlArray[b].setBounds(30, 20 + b+50, 80, 26);
jp.add(jlArray[b]);}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jbArray[0]){
int a=Integer.parseInt(jtxtName[0].getText())*Integer.parseInt(jtxtName[3].getText())+Integer.parseInt(jtxtName[1].getText())*Integer.parseInt(jtxtName[2].getText());
jtxtName[4].setText(Integer.toString(a));
int b=Integer.parseInt(jtxtName[1].getText())*Integer.parseInt(jtxtName[3].getText());
jtxtName[5].setText(Integer.toString(b));
}else if(e.getSource()==jbArray[1]){
int c=Integer.parseInt(jtxtName[0].getText())*Integer.parseInt(jtxtName[3].getText())-Integer.parseInt(jtxtName[1].getText())*Integer.parseInt(jtxtName[2].getText());
jtxtName[4].setText(Integer.toString(c));
int d=Integer.parseInt(jtxtName[1].getText())*Integer.parseInt(jtxtName[3].getText());
jtxtName[5].setText(Integer.toString(d));
}else if(e.getSource()==jbArray[3]){
int f=Integer.parseInt(jtxtName[0].getText())*Integer.parseInt(jtxtName[2].getText());
jtxtName[4].setText(Integer.toString(f));
int g=Integer.parseInt(jtxtName[1].getText())*Integer.parseInt(jtxtName[3].getText());
jtxtName[5].setText(Integer.toString(g));
}else if(e.getSource()==jbArray[3]){
int w=Integer.parseInt(jtxtName[0].getText())*Integer.parseInt(jtxtName[3].getText());
jtxtName[4].setText(Integer.toString(w));
int z=Integer.parseInt(jtxtName[1].getText())*Integer.parseInt(jtxtName[2].getText());
jtxtName[5].setText(Integer.toString(z));
}else{
jtxtName[0].setText("0");
jtxtName[1].setText("0");
jtxtName[2].setText("0");
jtxtName[3].setText("0");
jtxtName[4].setText("0");
jtxtName[5].setText("0");
}
}
}
希望大家可以帮帮忙,帮我看看是哪错了~最好能详细的指出来~~
[ 本帖最后由 绣球毛毛 于 2011-6-8 11:46 编辑 ]