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("关闭窗口");
}
}
}
}
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("关闭窗口");
}
}
}
}
解决方案 »
- 关于一个类调用另一个类的问题
- jfreechart如何给每个列生成一个超链接(是每个列)
- java去做界面是不是一定要写代码的?没有可视化的工具吗?
- readLine()是循环地往下读取行数据,怎么样才能在读取的过程中返回到首行呢,我不想重复打开和关闭文件
- Robocode 那里有的下
- 寻求现成的文本文件处理代码?
- 求救:由于Comm通讯的底层接口获取的int型整数数据是C++写的,现在要用java调用C++的接口int型出现溢出,即怎么获取大于2147483648(c++可
- server端主动断开连接导致client端close_wait问题
- 什么是UTF字符?
- 从其他语言转到JAVA,高手给推荐一本好书吧!
- 关于web.xml的配制问题
- 新建高级群,J2EE共同学习者进..
// fc.addWindowListener(new WinClose());
System.out.println("关闭窗口");
System.exit(0);
start=false;
fc.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}); System.out.println("关闭窗口");
改成fc.dispose
增加监听器的事件不要在监听器里面写了,你想dispose,直接在actionPerformed里面写好了
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();
}
}
}
}