void 的方法怎么能有return.
你可以在类中定义一个boolean.把booldean传出来呀。

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.event.*;
    public class aaa extends Frame implements ActionListener
    {
      Button  b1 = new Button("1");
      TextField output1 = new TextField(8);
        boolean  answer;
      
      public aaa() 
      {super("aaa");
      setLayout(new FlowLayout());
      add(b1);add(output1);
      b1.addActionListener(this);
      pack();
      show();}
      
        public static void main(String args[])
      {
       new aaa();
      }
        public void actionPerformed(ActionEvent e)
      {
       String ss;
       boolean flag;
      flag=true;
             
                     if(e.getSource()==b1)
            {
                if (flag==false) 
                {ss=output1.getText();output1.setText(ss+"1");}
          else     
           {output1.setText("1");}
                  flag=false;
                          answer =flag;
            }    
      }
    }
      

  2.   

    对了。在actionPerformed()方法中
    不能定义private boolean flag;
    要把private 去掉。
    传出来了。你看要怎么作什么 。?应该可以了吧。
      

  3.   

    恩好的,我差不多可以实现了,
     回复人: FGhost33(^用实力证明自己的存在!^) 
    你的程序的
    if (flag==false) 
    前面加上flag=answer;
    就OK了
      

  4.   

    结帖前我想除了这样的方法还有什么好的方法吗,
    还有3楼FGhost33(^用实力证明自己的存在!^) 的方法用了两个boolean
    能不能只用一个??????????????
      

  5.   

    import java.awt.*;
    import java.awt.event.*;
    public class aaa extends Frame implements ActionListener
    {
      Button  b1 = new Button("1");
      TextField output1 = new TextField(8);
      private boolean flag;
      public aaa() 
      {super("aaa");
      setLayout(new FlowLayout());
      add(b1);add(output1);
      b1.addActionListener(this);
      pack();
      show();}
      
        public static void main(String args[])
      {
       new aaa();
      }
        public void actionPerformed(ActionEvent e)
      {
       String ss;
     
      flag=true;
             
                     if(e.getSource()==b1)
            {
                if (flag==false) 
                {ss=output1.getText();output1.setText(ss+"1");}
          else     
           {output1.setText("1");}
                  flag=false;
            }    
      }
    }
      

  6.   

    你把private boolean flag;的定义放在类里,不要放在方法里就行啦。
    中午发完看你没回贴。我就睡觉去了。不好意思,现在才回复。