button1.addActionListener(new ActionListener() {
  public void actionPerformed() {
    button1.setText("thanks");
  }
}
);

解决方案 »

  1.   

    楼上,12个Jbutton,我如何才能获得他的操作权呢,我没有定义过button1
      

  2.   

    void jButton1_actionPerformed(ActionEvent e) {
    jButton1.setText("aaaaaaaaaaaaaa");  }你说得是这个吗?
      

  3.   

    private JButton jButton1 = new JButton();
    jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
    void jButton1_actionPerformed(ActionEvent e) {
    jButton1.setText("aaaaaaaaaaaaaa");
      }
    这样就可以了吧!!
      

  4.   

    public class Subblood extends JPanel {
      public Subblood(){
       this.setLayout(new FlowLayout(FlowLayout.LEFT,40,25));
       for(int i=1;i<=12;i++){
         JButton b=new JButton("guess me");
         b.addActionListener(new ActionListener() {
                        public void actionPerformed() {
                             button1.setText("thanks");
                                 }
                            }
                      );
         this.add(b);
       }
     this.setPreferredSize(new Dimension(500,200)); }
      

  5.   

    public class Subblood extends JPanel {
      public Subblood(){
       this.setLayout(new FlowLayout(FlowLayout.LEFT,40,25));
              for(int i=1;i<=12;i++){
                JButton jb=new JButton("guess me");
                jb.addActionListener(new ActionListener()  {
                  public void actionPerformed(ActionEvent e) {
                    JButton temp=(JButton)e.getSource();
                    temp.setText("thanks");
                  }
                });
                this.add(jb);
              } 
            this.setPreferredSize(new Dimension(500,200)); }