自己做了一个试了一下,可以运行,但是总觉得哪里不太对??哪位老大有Action接口的的例题吗?可以发上来看看不??
/** 这个程序是用来计算球员满时间48分钟绩效的*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class NBATest
{ public static void main(String[] args)
{ JFrame f = new NTFrame();
f.show();
}
}
class NTFrame extends JFrame
implements ActionListener
{ public NTFrame()
{ setTitle("NBATest");
setSize(500, 350);
showPanel = new JPanel();
buttonPanel = new JPanel();
Container contentPane = getContentPane();
contentPane.add(showPanel, "Center");
contentPane.add(buttonPanel, "South");
button = new JButton("sums");
buttonPanel.add(button);
button.addActionListener(this);
ppg = new JTextField(3);
rpg = new JTextField(3);
apg = new JTextField(3);
ppgf = new JTextField(3);
rpgf = new JTextField(3);
apgf = new JTextField(3);
min = new JTextField(3);
showPanel.add(ppg); // ppg 平均每场得分数
showPanel.add(rpg); // rpg 平均每场篮板数
showPanel.add(apg); // apg 平均每场助攻数
showPanel.add(min); // min 平均每场上场时间
showPanel.add(ppgf);
showPanel.add(rpgf);
showPanel.add(apgf);
ppgf.setEditable(false);
rpgf.setEditable(false);
apgf.setEditable(false);
}
public void actionPerformed(ActionEvent evt)
{ double pd = Double.parseDouble(ppg.getText());
double rd = Double.parseDouble(rpg.getText());
double ad = Double.parseDouble(apg.getText());
double md = Double.parseDouble(min.getText());
if (md == 0.0) { System.exit(0); }
DecimalFormat df = new DecimalFormat("0.##");
ppgf.setText("" + df.format(pd * 48 / md));
rpgf.setText("" + df.format(rd * 48 / md));
apgf.setText("" + df.format(ad * 48 / md));
}
private JPanel showPanel;
private JPanel buttonPanel;
private JButton button;
private JTextField ppg;
private JTextField rpg;
private JTextField apg;
private JTextField ppgf;
private JTextField rpgf;
private JTextField apgf;
private JTextField min;
}