求教一下关于我写的这个计算器程序
package zizhi;/**首先这个类的作用是计算器的按钮布局
* 里面包括了,数字键按钮,以及运算符的按钮
* 上面将是一个菜单栏,里面包括文件,编辑等……
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.TextField;
import javax.swing.text.JTextComponent;
public class jisuanqi1 extends JPanel
{
static final int WIDTH=400;
static final int HEIGHT=500;
JFrame jisuanqi;
public void add(Component c,GridBagConstraints constraints, int x,int y,int w,int h)
{
constraints.gridx=x;
constraints.gridy=y;
constraints.gridwidth=w;
constraints.gridheight=h;
add(c,constraints);
}
public jisuanqi1()
{
jisuanqi=new JFrame();
jisuanqi.setTitle("China--海涵工作室开发中心");
jisuanqi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jisuanqi.setSize(WIDTH,HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension ScreenSize=kit.getScreenSize();
int width=ScreenSize.width;
int height=ScreenSize.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
jisuanqi.setLocation(x, y);
jisuanqi.setVisible(true);
jisuanqi.show();
jisuanqi.add(this,BorderLayout.CENTER);
GridBagLayout lay=new GridBagLayout();
setLayout(lay);
JLabel title=new JLabel("周游的计算器");
JLabel czs1=new JLabel("操作数1:");
JLabel czs2=new JLabel("操作数2:");
JLabel jieguo=new JLabel("结 果:");
final JButton yi=new JButton("1");
yi.setEnabled(true);
yi.getText();
final JButton ling=new JButton("0");
ling.getText();
final JButton lingling=new JButton("00");
lingling.getText();
final JButton er=new JButton("2");
er.getText();
final JButton san=new JButton("3");
san.getText();
final JButton si=new JButton("4");
si.getText();
final JButton wu=new JButton("5");
wu.getText();
final JButton liu=new JButton ("6");
liu.getText();
final JButton qi=new JButton("7");
qi.getText();
final JButton ba=new JButton("8");
ba.getText();
final JButton jiu=new JButton("9");
jiu.getText();
final JButton jiafa=new JButton("+");
jiafa.getText();
final JButton jianfa=new JButton("—");
jianfa.getText();
final JButton chengfa=new JButton("*");
chengfa.getText();
final JButton chufa=new JButton("/");
chufa.getText();
final JButton guiling=new JButton("CE");
guiling.getText();
final JButton back=new JButton("Back");
back.getText();
final JButton c=new JButton("C");
c.getText();
final JButton zf=new JButton("+/-");
zf.getText();
final JButton queyu=new JButton("%");
// JButton bangzhu=new JButton("帮助");
final JButton dengyu=new JButton("=");
final JTextField czs11=new JTextField(10);
JTextField czs12=new JTextField(10);
JTextField jieguo1=new JTextField(10);
GridBagConstraints constraints=new GridBagConstraints();
constraints.fill=GridBagConstraints.NONE;
constraints.weightx=0;
constraints.weighty=0;
add(title,constraints,0,0,4,1);
add(czs1,constraints,0,1,1,1);
add(czs2,constraints,0,2,1,1);
add(jieguo,constraints,0,3,1,1);
add(czs11,constraints,1,1,4,1);
add(czs12,constraints,1,2,4,1);
add(jieguo1,constraints,1,3,4,1);
add(yi,constraints,0,4,1,1);
add(er,constraints,1,4,1,1);
add(san,constraints,2,4,1,1);
add(si,constraints,3,4,1,1);
add(wu,constraints,4,4,1,1);
add(liu,constraints,0,5,1,1);
add(qi,constraints,1,5,1,1);
add(ba,constraints,2,5,1,1);
add(jiu,constraints,3,5,1,1);
add(ling,constraints,4,5,1,1);
add(lingling,constraints,0,6,1,1);
add(jiafa,constraints,1,6,1,1);
add(jianfa,constraints,2,6,1,1);
add(chengfa,constraints,3,6,1,1);
add(chufa,constraints,4,6,1,1);
add(guiling,constraints,0,7,1,1);
add(zf,constraints,1,7,1,1);
add(dengyu,constraints,2,7,1,1);
add(queyu,constraints,3,7,1,1);
add(c,constraints,4,7,1,1);
yi.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent E)
{
JTextField czs11=new JTextField(10);
czs11.setText("JButton",yi);
}
});
er.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent E1)
{
JTextField cazs11=new JTextField(10);
czs11.setText("JButton",er);
}
});
}
public static void main(String args[])
{
jisuanqi1 jisuan=new jisuanqi1();
}
}
我想通过JButton传值到JTextFild文本框里面去。可是文本框里面没有setText()方法。求教