I'm new here, and I have a problem.
Several months ago, I've made a simple Color Eyedropper that picks colors from anywhere from the screen.
Now I'm making a Color Utility app that has many features like average color generating and mixing colors. Anyway, I thought adding this eyedropper would be cool, so I have a JButton in my JFrame that calls
DigitalEyedropper.init();
and creating another JFrame with my eyedropper.
It opens and runs, but I can't seem to get it to close. The default close button does not work. It doesn't seem listen for any JComponents. I tried to add a JButton to close the window, but it failed.
Can somebody help me?
public static JFrame window;
private static boolean cancel;
public void startProcess(){
Thread t = new Thread(this);
t.start();
}
public DigitalEyedropper(){
window = new JFrame();
window.setTitle("Color Utilty");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(640,360);
window.setVisible(true);
window.setLocationRelativeTo(null);
}
public static void init() throws InterruptedException, AWTException{
SwingUtilities.invokeLater(new DigitalEyedropper());
}
@Override
public void run() {
do{
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
try {
Robot picker = new Robot();
Color color = picker.getPixelColor(x, y);
window.setBackground(color);
}
catch (AWTException e) {
}
if(cancel){
System.out.println("breaking...");
//How to close the JFrame?
} while(/*What to do?*/)
}
}