0

私はウェブカメラ キャプチャ ライブラリと AWT を使用して、ウェブカメラから写真を撮るためのシンプルなインターフェイスを開発しています。ウィンドウを最小化した後、または別のウィンドウをその上に移動した後、JFrame のボタンとコンボボックスが消えます。フレームの上にポインターを移動すると、コンポーネントの可視性が復元されます。私は Java UI に熟練していません。コードの何が問題なのかわかりません。

    @SuppressWarnings("serial")
public class ImageCaptureManager extends JFrame {

    private class SkipCapture extends AbstractAction {

        public SkipCapture() {
            super(“Skip”);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            /*SOME CODE HERE*/

        }
    }

    private class SnapMeAction extends AbstractAction {

        public SnapMeAction() {
            super(“Snap”);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            /*SOME CODE HERE*/

        }
    }

    private class captureCompleted extends AbstractAction {

        public captureCompleted() {
            super(“Completed”);
        }

        @Override
        public void actionPerformed(ActionEvent e) {

            /*SOME CODE HERE*/
        }
    }

    private class saveImage extends AbstractAction {

        public saveImage() {
            super(“Save”);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            /*SOME CODE HERE*/
        }
    }

    private class deleteImage extends AbstractAction {

        public deleteImage() {
            super(“Delete”);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            /*SOME CODE HERE*/
        }
    }


    private class StartAction extends AbstractAction implements Runnable {

        public StartAction() {
            super(“Start”);
        }

        @Override
        public void actionPerformed(ActionEvent e) {

            btStart.setEnabled(false);
            btSnapMe.setEnabled(true);

            executor.execute(this);
        }

        @Override
        public void run() {
            panel.start();
        }
    }

    private Executor executor = Executors.newSingleThreadExecutor();

    private Dimension captureSize = new Dimension(640, 480);

    private Dimension displaySize = new Dimension(640, 480);


    private Webcam webcam = Webcam.getDefault();

    private WebcamPanel panel;

    private JButton btSnapMe = new JButton(new SnapMeAction());
    private JButton btStart = new JButton(new StartAction());

    private JButton btComplete = new JButton(new captureCompleted());
    private JButton btSave = new JButton(new saveImage());
    private JButton btDelete = new JButton(new deleteImage());
    private JButton btSkip = new JButton(new SkipCapture());

    private JComboBox comboBox = new JComboBox();


    public ImageCaptureManager() {
        super(“Frame”);

        this.addWindowListener( new WindowAdapter()
        {

            @Override
            public void windowDeiconified(WindowEvent arg0) {

            }
                public void windowClosing(WindowEvent e)
                {

                }
        });


        List<Webcam> webcams =  Webcam.getWebcams();
        for (Webcam webcam : webcams) {
            System.out.println(webcam.getName());
            if (webcam.getName().startsWith("USB2.0 Camera 1")) {
                this.webcam = webcam;
                break;
            }
        }


        panel = new WebcamPanel(webcam, displaySize, false);
        webcam.setViewSize(captureSize);

        panel.setFPSDisplayed(true);
        panel.setFillArea(true);

        btSnapMe.setEnabled(false);
        btSave.setEnabled(false);
        btDelete.setEnabled(false);


        setLayout(new FlowLayout());

        Panel buttonPanel = new Panel();
        buttonPanel.setLayout(new GridLayout(10, 1));
        buttonPanel.add(Box.createHorizontalStrut(20));
        buttonPanel.add(btSnapMe);
        buttonPanel.add(Box.createHorizontalStrut(20));
        buttonPanel.add(btSave);
        buttonPanel.add(Box.createHorizontalStrut(20));
        buttonPanel.add(btDelete);
        buttonPanel.add(Box.createHorizontalStrut(20));
        buttonPanel.add(btComplete);
        buttonPanel.add(Box.createHorizontalStrut(20));
        buttonPanel.add(btSkip);

        JLabel label1 = new JLabel("Test");
        label1.setText(“Bla bla bla”);
        JLabel label2 = new JLabel("Test");
        label2.setText(" ");

        Panel captionAndWebcamPanel = new Panel();
        captionAndWebcamPanel.add(label1);
        captionAndWebcamPanel.add(label2);
        captionAndWebcamPanel.add(panel);
        captionAndWebcamPanel.add(label2);
        captionAndWebcamPanel.add(comboBox);
        captionAndWebcamPanel.setLayout(new BoxLayout(captionAndWebcamPanel, BoxLayout.Y_AXIS));


        add(captionAndWebcamPanel);

        add(buttonPanel);
        pack();
        setVisible(true);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        btStart.doClick();

        setSize(900,600);

    }

}

4

1 に答える 1