package com.sun.media.protocol.screen; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.media.*; import javax.media.format.*; import javax.media.protocol.*; public class CaptureFrame extends JFrame { static final int FPS_INIT = 15; LiveStream stream = null; public void FrameTransmit(LiveStream s) { stream = s; } public CaptureFrame(String windowTitle) { super(windowTitle); //Create the slider and its label JLabel sliderLabel = new JLabel("Frames Per Second", JLabel.CENTER); sliderLabel.setAlignmentX(Component.CENTER_ALIGNMENT); JSlider framesPerSecond = new JSlider(JSlider.HORIZONTAL,0, 30, FPS_INIT); framesPerSecond.addChangeListener(new SliderListener()); //Turn on labels at major tick marks. framesPerSecond.setMajorTickSpacing(10); framesPerSecond.setMinorTickSpacing(1); framesPerSecond.setPaintTicks(true); framesPerSecond.setPaintLabels(true); framesPerSecond.setBorder( BorderFactory.createEmptyBorder(0,0,10,0)); //Put everything in the content pane. JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(sliderLabel); contentPane.add(framesPerSecond); contentPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); setContentPane(contentPane); //Add a listener for window events addWindowListener(new WindowAdapter() { public void windowIconified(WindowEvent e) { stream.pauseScreen = true;//stop screening while Iconified } public void windowDeiconified(WindowEvent e) { stream.pauseScreen = false;//resume screening while deIconified } public void windowActivated(WindowEvent e) { //displayMessage("Window activated"); } public void windowDeactivated(WindowEvent e) { //displayMessage("Window deactivated"); } public void windowOpened(WindowEvent e) { //displayMessage("Window opened"); } public void windowClosing(WindowEvent e) { System.out.println("window closed"); System.exit(0); } public void windowClosed(WindowEvent e) { //displayMessage("Window closed"); } }); addComponentListener(new ComponentAdapter() { public void componentHidden(ComponentEvent e) { //displayMessage("componentHidden "); } public void componentMoved(ComponentEvent e) { Point pp = e.getComponent().getLocation(); int X = (int) pp.getX(); int Y = (int) pp.getY(); stream.setPoint((int) pp.getX(), (int) pp.getY()); System.out.println("new frame X and Y are: " + X + " , " + Y); } public void componentResized(ComponentEvent e) { Dimension dm = e.getComponent().getSize(); try { int tms = (int) dm.getWidth()/8; int width = tms*8; tms = (int) dm.getHeight()/8; int height = tms*8; stream.setDimension(width, height); System.out.println("new frame width and height: " + width + " , " + height); } catch (Exception ioe) { } } public void componentShown(ComponentEvent e) { //displayMessage("componentShown"); } }); } /** Listens to the slider. */ class SliderListener implements ChangeListener { public void stateChanged(ChangeEvent e) { JSlider source = (JSlider)e.getSource(); if (!source.getValueIsAdjusting()) { float ffps = (float) source.getValue(); stream.setFrameRate(ffps); System.out.println("new frame rate is: " + ffps); } } } }