import java.awt.*;
import java.awt.event.*;
class MyWindow extends Frame implements ActionListener
{ Button b[]=new Button[10];//new 0至9的按钮
Button button01,button02,button03,button04;
TextField text1;
int x,y,i;
MyWindow(String s)
{
super(s);
button01=new Button("加");
button02=new Button("减");
button03=new Button("乘");
button04=new Button("除");
text1=new TextField(12);
setLayout(new FlowLayout());
add(text1);
for(i=0;i<10;i++)
{b[i]=new Button(Integer.toString(i));
b[i].addActionListener(this);
add(b[i]);
}//生成0至9的按钮
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
add(button01);
add(button02);
add(button03);
add(button04);
//button01.addActionListener;
//button02.addActionListener;
//button03.addActionListener;
//button04.addActionListener;
setBounds(100,100,250,300);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b[i])
{
text1.setText(b[i].getLabel());
}
}
}
public class JiShuangQi03
{
public static void main(String args[])
{new MyWindow("计算器");
}
}
我运行后为什么我单击0至9的按钮 文本框中不显示数字
不会告诉我0至9的按钮要一个一个new Button()才可以用吧