不能一次点击JButton的蓝色

时间:2015-08-16 02:52:56

标签: java jbutton action actionlistener

当我在ButtonSample类中运行main时,按钮会弹出并按预期工作,但不能多次单击它。导致这种情况发生的原因以及我应该更改什么才能使其正常工作并且可以多次单击该按钮。是否与我的actionListener有关。此外,当我尝试单击退出按钮时按钮不会关闭,直到我重置Java虚拟机,我将如何修复它。

import java.io.*;
import javax.swing.*;
import java.awt.event.*;
public class ButtonSample extends JFrame implements ActionListener  
{  
    String[] et = {};
    JButton button1;
    public ButtonSample() throws IOException 
    {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(100, 100);
        setLocation(100, 100);

        button1 = new JButton("GO");
        button1.addActionListener(this);
        add(button1);

        setVisible(true);
    } 

    public static void main(String[] args) throws IOException 
    {
         new ButtonSample();
    }

    @Override
    public final void actionPerformed(ActionEvent e) //throws IOException
    {
        try{
        String command = e.getActionCommand();
        String[] arr = {};

        if(command.equals("GO")) {
        tester.main(arr);

    }
    }catch(IOException io){ }
  }
}



public class tester 
{
    public static void main(String[] args) throws IOException
    {
        String[] err = {};
        try
        {
          boolean go = true;
          Scanner in = new Scanner(System.in);
          while(go)
          {
            Reader r = new Reader();
            Three t = new Three();
            String[] run = {};
            String[] list = Reader.main(run);
            int one = t.get1();
            int two = t.get2();
            int three = t.get3();
            t.check(one, two, three);
            System.out.println("The three names are...");
            System.out.println(list[one] + "    " + list[two] + "    " +       list[three]);
            System.out.print("Play again?(Y/N): ");
            String check = in.next();
            if(check.equals("n") || check.equals("N"))
            {
               go = false;
               System.exit(0);
            }
            System.out.print('\u000C');
          }
        } catch (StackOverflowError e) 
          {
              System.out.print('\u000C');
              tester.main(err);
          }
    }
}

0 个答案:

没有答案