|
| 1 | +import java.awt.FlowLayout; |
| 2 | +import java.awt.event.ActionEvent; |
| 3 | + |
| 4 | +import javax.swing.AbstractAction; |
| 5 | +import javax.swing.JCheckBox; |
| 6 | +import javax.swing.JFrame; |
| 7 | + |
| 8 | +import com.github.sarxos.webcam.Webcam; |
| 9 | +import com.github.sarxos.webcam.WebcamPanel; |
| 10 | +import com.github.sarxos.webcam.WebcamResolution; |
| 11 | + |
| 12 | + |
| 13 | +@SuppressWarnings("serial") |
| 14 | +public class WebcamPanelFlippingExample { |
| 15 | + |
| 16 | + public static void main(String[] args) throws InterruptedException { |
| 17 | + |
| 18 | + final Webcam webcam = Webcam.getDefault(); |
| 19 | + webcam.setViewSize(WebcamResolution.QVGA.getSize()); |
| 20 | + |
| 21 | + final WebcamPanel panel = new WebcamPanel(webcam); |
| 22 | + panel.setFPSDisplayed(true); |
| 23 | + panel.setImageSizeDisplayed(true); |
| 24 | + panel.setMirrored(true); |
| 25 | + |
| 26 | + final JCheckBox flip = new JCheckBox(); |
| 27 | + flip.setSelected(true); |
| 28 | + flip.setAction(new AbstractAction("Flip") { |
| 29 | + |
| 30 | + @Override |
| 31 | + public void actionPerformed(ActionEvent e) { |
| 32 | + panel.setMirrored(flip.isSelected()); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + JFrame window = new JFrame("Test webcam panel"); |
| 37 | + window.setLayout(new FlowLayout()); |
| 38 | + window.add(panel); |
| 39 | + window.add(flip); |
| 40 | + window.setResizable(true); |
| 41 | + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 42 | + window.pack(); |
| 43 | + window.setVisible(true); |
| 44 | + } |
| 45 | +} |
0 commit comments