日期:2014-05-20  浏览次数:20743 次

做一个计算器时遇到小难题,请高手帮忙。。。。。
public class CalculatorFrame extends JFrame implements ActionListener {
   
  /**
  * The constructor.
  */  
   
  JTextField jtf = new JTextField();
   
  public CalculatorFrame() {
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  Container c = this.getContentPane();
  JPanel jpl = new JPanel();
  c.add(jtf,BorderLayout.NORTH);
  c.add(jpl,BorderLayout.CENTER);
  jpl.setLayout(new GridLayout(4,4));
  JButton b = null;
  for(int i=1;i<4;i++)
  { 
   
  b = new JButton(i);
  b.addActionListener(this);
  jpl.add(b);
  }
   

就到这了问题就出来了。在按钮中不能出现1,2,3的对应数字。二十都是出现i这个字符。。。请问怎么将字符i 转换成整数输出???????????

------解决方案--------------------
b = new JButton(i+"");这样呢?