显示在文本框中。已经给出部分代码,请完成事件处理部分。
import j avax. swing. *;
import Java. awt. event. *;
class MiYal extends JPanel
{
JButton button[] =new JButton[3] ;
JTextField text;
MiYal()
{
for(int i=0; i<3; i++)
{
button[i] =new JButton("button0"+(i+1) ) ;
add(button[i] ) ;
}
text=new JTextField(10) ;
text. setHorizontalAlignment(JTextField. CENTER) ;
add(text) ;
}
}
public class C3801 implements ActionListener
{
JFrame. myWin:
MiYal panel;
C3801()
{
panel=new MiYal() ;
myWin=new JFrame("C3801") ;
myWin. add(panel) ;
myWin. setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE. ;
for(int i=0; i<3; i++)
panel. button[i] . addActionListener(this) ;
myWin. pack() ;
myWin. setVisible(true) ;
}
public stalic void main(String[] args)
{
new C3801() ;
}
public void actionPerformed(ActionEvent e)
{
//这里是你要编写的代码
}
}