Есть код:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
package ru.nextep.webcam;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UI extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private static WebcamControl wc = new WebcamControl();
private JPanel controlPane = new JPanel();
private JPanel timerPane = new JPanel();
private JLabel threeLabel = new JLabel("3");
private JLabel twoLabel = new JLabel("2");
private JLabel oneLabel = new JLabel("1");
private JLabel[] labelArray = {threeLabel, twoLabel, oneLabel};
public UI (){
setLayout( new BoxLayout( this , BoxLayout.Y_AXIS));
JPanel videoPane = new JPanel();
videoPane.add(wc.getVideo());
add(videoPane);
controlPane.setLayout( new BoxLayout(controlPane, BoxLayout.X_AXIS));
controlPane.setBorder(BorderFactory.createEmptyBorder( 0 , 10 , 10 , 10 ));
JButton photoButton = new JButton("Сделать снимок");
photoButton.setActionCommand("makePhoto");
photoButton.addActionListener( this );
JButton exitButton = new JButton("Выход");
exitButton.setActionCommand("exit");
exitButton.addActionListener( this );
controlPane.add(photoButton);
controlPane.add(Box.createRigidArea( new Dimension( 10 , 0 )));
controlPane.add(exitButton);
add(controlPane);
timerPane.setLayout( new BoxLayout(timerPane, BoxLayout.X_AXIS));
timerPane.setBorder(BorderFactory.createEmptyBorder( 0 , 10 , 10 , 10 ));
for (JLabel label : labelArray){
label.setVisible(false);
timerPane.add(label);
}
add(timerPane);
}
private static void createAndShowGUI(){
JFrame frame = new JFrame();
frame.setBounds( 0 , 0 , 600 , 560 );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
UI newContentPane = new UI();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
frame.setVisible(true);
frame.pack();
}
public static void main(String args[]){
javax.swing.SwingUtilities.invokeLater( new Runnable(){
public void run(){
createAndShowGUI();
};
});
}
public void actionPerformed(ActionEvent ae) {
if ("makePhoto".equals(ae.getActionCommand())){
controlPane.setVisible(false);
timerPane.setVisible(true);
for (JLabel label : labelArray){
try {
Thread.sleep( 1000 );
} catch (InterruptedException e) {
e.printStackTrace();
}
label.setVisible(true);
}
wc.makePhoto();
}
if ("exit".equals(ae.getActionCommand())){
System.exit( 0 );
}
}
}
Вообщем небольшая свинг-апп. Вебкам - класс взаимодействия с веб-камерой(если закомментировать его использование в 2-3 местах, то код работоспособен). Всё работает, но одно "но". Я хочу что бы при нажатии кнопки для создания снимка - панель с кнопками пропадала и начинался отсчёт 3-2-1. Но вместо этого при нажатии кнопки действия эти происходят где-то на фоне(перед глазами панель контрол с зажатой кнопкой) и я просто через 3 секукнды уже получаю панель с 321. Колдовал с validate & repaint, не помогло.