import java.awt.*;
import java.awt.event.*;import javax.swing.JOptionPane;//导入界面对话显示窗体类JoptionPane
public class Hello{ private static Frame fc;
private static Button b1;
private static Button b2;
private static boolean start=false;
private static int minuteInput;
private static int minuteSwitch;
private static int i=0;
private static String gradeString;

public static void main(String[] args) throws AWTException{

//input seconds of interval
gradeString = JOptionPane.showInputDialog( 
        "Enter seconds: " );
minuteInput=Integer.parseInt( gradeString );
minuteSwitch=minuteInput*1000;

fc = new Frame("点点点");
fc.setLayout(new FlowLayout());
 
b1 = new Button("GO");
b2 = new Button("Stop");
b1.addActionListener(new Bb());
b2.addActionListener(new Bb());

fc.add(b1);
fc.add(b2);
fc.pack();
fc.setVisible(true);
fc.addWindowListener(new WinClose());

//fc.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){fc.dispose();}});
}

public static class WinClose extends WindowAdapter{
public void windowClosing(WindowEvent e) {
fc.dispose();
}
}

public static class Bb extends WindowAdapter implements ActionListener
{

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1) 
{
start=true;
while(start==true) 
{
try {
Robot r=new Robot();
r.mouseMove(288,288);//将鼠标移至屏幕坐标(288,288)
r.delay(minuteSwitch);//停留
r.mousePress(InputEvent.BUTTON1_MASK);//按下鼠标左键
r.delay(100);
r.mouseRelease(InputEvent.BUTTON1_MASK);//松开左键
}catch(Exception AWTException){
JOptionPane.showMessageDialog(fc, "It is not supported by your System!!!");
}
}
}

else if(e.getSource()==b2) {  // *****************为什么这里关不窗口的?????????????????????????
start=false;
fc.addWindowListener(new WinClose());
System.out.println("关闭窗口");
}
}
}
}

解决方案 »

  1.   

    这样就可以了
    // fc.addWindowListener(new WinClose());
    System.out.println("关闭窗口");
    System.exit(0);
      

  2.   

    如果你是要点stop后再点X关闭,用这个
    start=false;
    fc.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                   System.exit(0);
               }
             }); System.out.println("关闭窗口");
      

  3.   

    把你的fc.addWindowListener(new WinClose());
    改成fc.dispose
      

  4.   

    楼主,你的程序写得不太好啊你认为出错的地方其实又没干什么事情,只不过fc.addWindowListener,增加了监听器而已,又没调用函数,
    增加监听器的事件不要在监听器里面写了,你想dispose,直接在actionPerformed里面写好了
      

  5.   

    import java.awt.*;
    import java.awt.event.*;import javax.swing.JOptionPane;//导入界面对话显示窗体类JoptionPanepublic class Hello { private static Frame fc; private static Button b1; private static Button b2; private static boolean start = false; private static int minuteInput; private static int minuteSwitch; private static int i = 0; private static String gradeString; public Hello() { // input seconds of interval
    gradeString = JOptionPane.showInputDialog("Enter seconds: ");
    minuteInput = Integer.parseInt(gradeString);
    minuteSwitch = minuteInput * 1000; fc = new Frame("点点点");
    fc.setLayout(new FlowLayout()); b1 = new Button("GO");
    b2 = new Button("Stop");
    b1.addActionListener(new Bb());
    b2.addActionListener(new Bb()); fc.add(b1);
    fc.add(b2);
    fc.pack();
    fc.setVisible(true);
    fc.addWindowListener(new WinClose()); // fc.addWindowListener(new WindowAdapter(){public void
    // windowClosing(WindowEvent e){fc.dispose();}}); } public static void main(String[] args) {
    new Hello();
    } class WinClose extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
    fc.dispose();
    }
    } class Bb implements ActionListener { public void actionPerformed(ActionEvent e) {
    if (e.getSource() == b1) {
    start = true;
    while (start == true) {
    try {
    Robot r = new Robot();
    r.mouseMove(288, 288);// 将鼠标移至屏幕坐标(288,288)
    r.delay(minuteSwitch);// 停留
    r.mousePress(InputEvent.BUTTON1_MASK);// 按下鼠标左键
    r.delay(100);
    r.mouseRelease(InputEvent.BUTTON1_MASK);// 松开左键
    } catch (Exception AWTException) {
    JOptionPane.showMessageDialog(fc,
    "It is not supported by your System!!!");
    }
    }
    } else if (e.getSource() == b2) { // *****************为什么这里关不窗口的?????????????????????????
    start = false;
    System.out.println("关闭窗口");
    fc.dispose();
    }
    }
    }
    }
      

  6.   

    很是谢谢 believefym(feng) 这位大哥把我的程序整理了一遍....我以后都会学着按这样写程序..真是非常感谢