Internetning o'sishi bilan usulda tub o'zgarishlar yuz ber dasturiy ta'minotni loyihalash va joylashtirish. Dasturiy ta'minot dasturlari tobora ko'proq tarqalmoqda
Download 0.93 Mb.
|
1 2
Bog'liq2-Mustaqil Ishi
- Bu sahifa navigatsiya:
- Foydalanilgan adabiyotlar
Amaliy qism
import java.awt.*; import java.net.MalformedURLException; import javax.media.*; import javax.swing.JFrame; public class captureCAM { @SuppressWarnings("UseSpecificCatch") public static void main(String[] args) throws MalformedURLException { CaptureDeviceInfowebcamInfooo=newCaptureDeviceInfo("Camera", new MediaLocator("vfw://0"),null); MediaLocator webcamMediaLocator =webcamInfooo.getLocator; Player player; try { player = Manager.createRealizedPlayer(webcamMediaLocator); Component comp; if ((comp = player.getVisualComponent()) != null) { JFrame f = new JFrame("test :)"); f.setLayout(new BorderLayout()); f.add(comp, BorderLayout.CENTER); f.add(player.getControlPanelComponent(), BorderLayout.SOUTH); f.setSize(400,400); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); player.start(); } } catch (Exception x) { } } } Dastur Natijalari import java.awt.*; import java.awt.event.*; import java.net.URL; import javax.media.*; import javax.media.rtp.*; import javax.swing.*; public class PlayFileUsingJMF { @SuppressWarnings("UseSpecificCatch") public static void main(String[] args) throws InvalidSessionAddressException { //code below is used to make JAVA programs look more friendly try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { } // we are creating file chooser to load some media file 20 JFileChooser file = new JFileChooser(); int option = file.showOpenDialog(null); try { URL url = null; // now after the choice is made, we extract the URL from it if (option == JFileChooser.APPROVE_OPTION) { url = file.getSelectedFile().toURL(); } final Player player Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true); // here we are using Manager class to create a Player from our URL player = Manager.createRealizedPlayer(url); // now we are simply constructing a frame to display our player JFrame f = new JFrame("test :)"); f.setLayout(new BorderLayout()); // well, that's important: we are adding the player's visual component to the frame f.add(player.getVisualComponent(), BorderLayout.CENTER); // important: here we are adding the control component of the player f.add(player.getControlPanelComponent(), BorderLayout.SOUTH); // TO here we are ready to go ! the buttons are optional but we want to // show them, in case someone doesn't like to use the default controller // here we are defining some buttons that we will use JPanel pan = new JPanel(); JButton start = new JButton("start"); JButton stop = new JButton("stop"); JButton pause = new JButton("pause"); pan.add(start); pan.add(stop); pan.add(pause); add(pan, BorderLayout.SOUTH); start.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // when play button is pressed we simply start the player! player.start(); } }); stop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { player.stop(); player.deallocate(); // release resources too } }); pause.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { player.stop(); } }); 8// initializing our frame f.setSize(400, 400); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); player.start(); } catch (Exception ex) { } } } Natija Foydalanilgan adabiyotlar Download 0.93 Mb. Do'stlaringiz bilan baham: |
1 2
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling