0

私はここに来たばかりで、問題があります。
数か月前、画面のどこからでも色を選択できるシンプルな Color Eyedropper を作成しました。
現在、平均的な色の生成や色の混合などの多くの機能を備えた Color Utility アプリを作成しています。とにかく、このスポイトを追加するのはクールだと思ったので、JFrame に呼び出す JButton があります。

DigitalEyedropper.init();

スポイトで別の JFrame を作成します。
開いて動きますが、閉じることができないようです。デフォルトの閉じるボタンは機能しません。JComponents をリッスンしていないようです。ウィンドウを閉じるために JButton を追加しようとしましたが、失敗しました。

誰か助けてくれませんか?

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?*/)
    }
}   
4

0 に答える 0