الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

دمج بين كودين جافا

بدأه dgtal_01 في 13 أبريل 2008 · 4 رد · 575 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

أخواني الأعزاء مبرمجي الجافا الموقرين السلام عليكم ورحمة الله وبركاته ..... أما بعد :-

عندي مشروع وهو صناعة Control Buttons و Image Capture للمقطع الفيديو Quick Time

الأكواد Control Buttons و Image Capture موجودة لكن المشكلة التي أواجهها هي في دمج الكوديين

الكود الأول (الرئيسي): MyPlayMovie وهو الخاص بـ Control Buttons

الكود الثاني: MyImagePresenter وهو الخاص بـ Image Capture

أريد فقط إضافة الكود الثاني على هيئة Button في الكود الأول

الكود الأول (الرئيسي):

// MyPlayMovie

//Simplest QTJ program

import java.awt.*;

import java.awt.event.*;

import quicktime.*;

import quicktime.io.*;

import quicktime.std.movies.*;

import quicktime.app.view.*;

public class MyPlayMovie extends Frame implements ActionListener, Errors{

Button revButton,

stopButton,

startButton,

fwdButton,

capButton;

Movie theMovie;

public static void main (String args[]) {

try {

QTSession.open();

MyPlayMovie pm = new MyPlayMovie("QT in Java");

pm.pack();

pm.show();

pm.toFront();

} catch (QTException e) {

e.printStackTrace();

QTSession.close ();

}

}

MyPlayMovie (String title) throws QTException {

super (title);

// prompt the user to select a movie file

QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);

// open the file and make the movie from it

OpenMovieFile moviefile = OpenMovieFile.asRead(qtf);

Movie m = Movie.fromFile(moviefile);

theMovie = m;

// construct a movie controller from the movie

//enable the keyboard so the user can interact with it

MovieController mc = new MovieController(m);

mc.setKeysEnabled (true);

// create and add a QTComponent and set qtc's movie controller

QTComponent qtc = QTFactory.makeQTComponent(mc);

Component c = qtc.asComponent();

//add((Component)qtc);

add (c, BorderLayout.CENTER);

Panel buttons = new Panel();

revButton = new Button("Back");

revButton.addActionListener (this);

stopButton = new Button ("Stop");

stopButton.addActionListener (this);

startButton = new Button ("Play");

startButton.addActionListener (this);

fwdButton = new Button ("Forward");

fwdButton.addActionListener (this);

capButton = new Button ("Capture");

capButton.addActionListener (this);

buttons.add (revButton);

buttons.add (stopButton);

buttons.add (startButton);

buttons.add (fwdButton);

buttons.add (capButton);

add (buttons, BorderLayout.SOUTH);

pack();

//user closes the window, listener terminates QT session, disposes of frame and program quits

addWindowListener(new WindowAdapter() { //an anonymnous inner class

public void windowClosing(WindowEvent we) { //overide method

QTSession.close();

dispose(); //dispose of window

}

public void windowClosed(WindowEvent we) {

System.exit(0); //quit the program

}

});

}

public void actionPerformed (ActionEvent e) {

try {

if (e.getSource() == revButton)

theMovie.setRate (theMovie.getRate() - 1.0f);

else if (e.getSource() == stopButton)

theMovie.stop();

else if (e.getSource() == startButton)

theMovie.start();

else if (e.getSource() == capButton)

theMovie.start();

else if (e.getSource() == fwdButton)

theMovie.setRate (theMovie.getRate() + 1.0f);

} catch (QTException qte) {

qte.printStackTrace();

}

}

}

الكود الثاني ()

// MyImagePresenter.java

//Captures an image from a movie as a PICT, converts it to look like a PICT file

//constructs a GraphicsImporterDrawer, constructs a QTImageProducer,

//then constructs a Java Image and displays it on a Java Canvas with a drawImage in Paint()

//

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.io.IOException;

import quicktime.*;

import quicktime.io.*;

import quicktime.qd.*;

import quicktime.std.*;

import quicktime.std.movies.*;

import quicktime.std.movies.media.*;

import quicktime.app.view.*;

import quicktime.std.image.*;

public class MyImagePresenter extends Frame {

public static void main (String args[]) {

try {

System.out.println("Image Capture from Movie to Java Images");

QTSession.open();

MyImagePresenter pm = new MyImagePresenter("Image Capture from Movie to Java Images");

pm.show();

pm.toFront();

} catch (QTException e) {

System.out.println("QT init problem");

e.printStackTrace();

QTSession.close ();

}

}

MyImagePresenter (String title) throws QTException {

super (title);

final Canvas mCanvas = new Canvas(); //get a Java canvas for the image

ip.setSize(450, 400);

ip.add(mCanvas);

add(ip, "West");

MenuBar menuBar = new MenuBar(); //get a menu

Menu captureMenu = new Menu ("Capture");

MenuItem nowMenuItem = new MenuItem ("Now");

captureMenu.add(nowMenuItem);

menuBar.add (captureMenu);

this.setMenuBar (menuBar);

//prompt the user to select a movie file

QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);

//open the file and make the movie from it

OpenMovieFile moviefile = OpenMovieFile.asRead(qtf);

m = Movie.fromFile(moviefile);

//construct a movie controller from the movie

MovieController mc = new MovieController(m);

mc.setKeysEnabled (true);

//create a QT Component so the movie controller has a place to draw

//add it to a panel, add the panel to the frame

QTComponent qtc = QTFactory.makeQTComponent(mc);

mp.setSize(mc.getBounds().getWidth()+20, mc.getBounds().getHeight()+40);

mp.add((Component)qtc);

add(mp, "East");

//set the bounds of the Frame based on the dimensions of the movie

setBounds(0,0, mc.getBounds().getWidth() +300, mc.getBounds().getHeight() +40);

nowMenuItem.addActionListener (new ActionListener () {

public void actionPerformed(ActionEvent event) {

//this is where the image work is done

try {

System.out.println("Movie Time" + m.getTime());

Pict mpict = m.getPict(m.getTime()); //get PICT from current frame

//As there is no constructor to make an image from a PICT we have to

// pretend we have a PICT file by adding 512 bytes header to PICT

byte[] newPictBytes = new byte [mpict.getSize() + 512];

mpict.copyToArray (0, newPictBytes, 512, newPictBytes.length - 512);

mpict = new Pict (newPictBytes);

//get a Dataref to the PICT - structure in movie toolbox

DataRef ref = new DataRef (mpict, StdQTConstants.kDataRefQTFileTypeTag, "PICT");

// make a graphicsImporterDrawer from the dataref to represent an image that is stored as a file

// that can be read and drawn using QuickTime GraphicsImporter component

GraphicsImporterDrawer gid = new GraphicsImporterDrawer(ref);

//Create a QTImageProducer from the GraphicsImporterDrawer to produce the image for drawing

QDRect rect = gid.getDisplayBounds();

Dimension dim = new Dimension (rect.getWidth(), rect.getHeight());

aspect = (float)rect.getWidth() / (float)rect.getHeight();

System.out.println("Aspect ratio is " + aspect);

QTImageProducer qtip = new QTImageProducer (gid, dim);

// From the QTImageProducer create a Java image for drawing

javaImage = Toolkit.getDefaultToolkit().createImage(qtip);

caught = true; //stops paint trying to draw a non existant image

repaint(); //calls paint () to display Java image on Java canvas

} catch (QTException ea) { //close down QT because there was a problem

System.out.println("Exception in capture menu");

ea.printStackTrace();

QTSession.close ();

}

}

});

//When the user closes the window, the window listener terminates the QT session,

//disposes of the frame and the program quits

addWindowListener(new WindowAdapter () {

public void windowClosing (WindowEvent e) {

QTSession.close();

dispose();

}

public void windowClosed(WindowEvent e) {

System.exit(0);

}

});

}

public void paint(Graphics g) {

// System.out.println("Paint");

if (caught) { //protect against trying to draw no image

System.out.println("Paint after caught");

int width = getSize().width;

int height = getSize().height;

g.drawImage(javaImage,20,50, (int)(aspect * 60.0) , 60 , null); //paint Java image

}

};

//use of public variables not normally encouraged

public Image javaImage;

public Movie m;

public boolean caught = false;

public Panel mp = new Panel();

public Panel ip = new Panel();

public GraphicsImporter gi = new GraphicsImporter (StdQTConstants.kQTFileTypePicture);

public GraphicsImporterDrawer gid = new GraphicsImporterDrawer (gi);

public float aspect = (float)16/(float)9;

}

أرجوكم بحاجة للإجابة في غاية السرعة

please

#2

ممكن شوية ترتيب اخوي العزيز

وشرح اكتر للاكواد ..

الله معك.

#3

هذا تعديل بسيط ارجو ان يكون صحيح ... او كما هو مطلوب ...حيث اني لم أجرب التعديل

import java.awt.*;

import java.awt.event.*;

import quicktime.*;

import quicktime.io.*;

import quicktime.std.movies.*;

import quicktime.app.view.*;



public class MyPlayMovie extends Frame implements ActionListener, Errors{



Button revButton,

stopButton,

startButton,

fwdButton,

capButton;

Movie theMovie;







public static void main (String args[]) 
{

try {

QTSession.open();

MyPlayMovie pm = new MyPlayMovie("QT in Java");

pm.pack();

pm.show();

pm.toFront();

} catch (QTException e) {

e.printStackTrace();

QTSession.close ();

}

}



MyPlayMovie (String title) throws QTException {

super (title);

// prompt the user to select a movie file

QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);



// open the file and make the movie from it

OpenMovieFile moviefile = OpenMovieFile.asRead(qtf);

Movie m = Movie.fromFile(moviefile);

theMovie = m;



// construct a movie controller from the movie

//enable the keyboard so the user can interact with it

MovieController mc = new MovieController(m);

mc.setKeysEnabled (true);



// create and add a QTComponent and set qtc's movie controller

QTComponent qtc = QTFactory.makeQTComponent(mc);

component c = qtc.asComponent();

//add((Component)qtc);



add (c, BorderLayout.CENTER);

Panel buttons = new Panel();

revButton = new Button("Back");

revButton.addActionListener (this);

stopButton = new Button ("Stop");

stopButton.addActionListener (this);

startButton = new Button ("Play");

startButton.addActionListener (this);

fwdButton = new Button ("Forward");

fwdButton.addActionListener (this);

capButton = new Button ("Capture");

capButton.addActionListener (this);

buttons.add (revButton);

buttons.add (stopButton);

buttons.add (startButton);

buttons.add (fwdButton);

buttons.add (capButton);

add (buttons, BorderLayout.SOUTH);



pack();



//user closes the window, listener terminates QT session, disposes of frame and program quits



addWindowListener(new WindowAdapter() { //an anonymnous inner class

public void windowClosing(WindowEvent we) { //overide Method

QTSession.close();

dispose(); //dispose of window

}

public void windowClosed(WindowEvent we) {

System.exit(0); //quit the program

}

});



}

public void actionPerformed (ActionEvent e) {

try {

if (e.getSource() == revButton)

theMovie.setRate (theMovie.getRate() - 1.0f);

else if (e.getSource() == stopButton)

theMovie.stop();

else if (e.getSource() == startButton)

theMovie.start();

else if (e.getSource() == capButton)
{
MyImagePresenter pm = new MyImagePresenter("Image Capture from Movie to Java Images");

pm.show();

pm.toFront();

theMovie.start();
}


else if (e.getSource() == fwdButton)

theMovie.setRate (theMovie.getRate() + 1.0f);

} catch (QTException qte) {

qte.printStackTrace();

}

}

}
//////////////////////////////

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.io.IOException;



import quicktime.*;

import quicktime.io.*;

import quicktime.qd.*;

import quicktime.std.*;

import quicktime.std.movies.*;

import quicktime.std.movies.media.*;

import quicktime.app.view.*;

import quicktime.std.image.*;



public class MyImagePresenter extends Frame {
/*
public static void main (String args[]) {

try {

System.out.println("Image Capture from Movie to Java Images");

QTSession.open();

MyImagePresenter pm = new MyImagePresenter("Image Capture from Movie to Java Images");

pm.show();

pm.toFront();

} catch (QTException e) {

System.out.println("QT init problem");

e.printStackTrace();

QTSession.close ();

}

}

*/

MyImagePresenter (String title) throws QTException {

super (title);

try {

System.out.println("Image Capture from Movie to Java Images");

QTSession.open();


} catch (QTException e) {

System.out.println("QT init problem");

e.printStackTrace();

QTSession.close ();

}

final Canvas mCanvas = new Canvas(); //get a Java canvas for the image

ip.setSize(450, 400);

ip.add(mCanvas);

add(ip, "West");



MenuBar menuBar = new MenuBar(); //get a menu

Menu captureMenu = new Menu ("Capture");

MenuItem nowMenuItem = new MenuItem ("Now");

captureMenu.add(nowMenuItem);

menuBar.add (captureMenu);

this.setMenuBar (menuBar);



//prompt the user to select a movie file

QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);



//open the file and make the movie from it

OpenMovieFile moviefile = OpenMovieFile.asRead(qtf);

m = Movie.fromFile(moviefile);



//construct a movie controller from the movie

MovieController mc = new MovieController(m);

mc.setKeysEnabled (true);



//create a QT component so the movie controller has a place to draw

//add it to a panel, add the panel to the frame

QTComponent qtc = QTFactory.makeQTComponent(mc);

mp.setSize(mc.getBounds().getWidth()+20, mc.getBounds().getHeight()+40);

mp.add((Component)qtc);

add(mp, "East");

//set the bounds of the Frame based on the dimensions of the movie

setBounds(0,0, mc.getBounds().getWidth() +300, mc.getBounds().getHeight() +40);



nowMenuItem.addActionListener (new ActionListener () {

public void actionPerformed(ActionEvent event) {

//this is where the image work is done

try {

System.out.println("Movie Time" + m.getTime());



Pict mpict = m.getPict(m.getTime()); //get PICT from current frame

//As there is no Constructor to make an image from a PICT we have to

// pretend we have a PICT file by adding 512 bytes header to PICT

byte[] newPictBytes = new byte [mpict.getSize() + 512];

mpict.copyToArray (0, newPictBytes, 512, newPictBytes.length - 512);

mpict = new Pict (newPictBytes);

//get a Dataref to the PICT - structure in movie toolbox

DataRef ref = new DataRef (mpict, StdQTConstants.kDataRefQTFileTypeTag, "PICT");



// make a graphicsImporterDrawer from the dataref to represent an image that is stored as a file

// that can be read and drawn using QuickTime GraphicsImporter component

GraphicsImporterDrawer gid = new GraphicsImporterDrawer(ref);

//Create a QTImageProducer from the GraphicsImporterDrawer to produce the image for drawing

QDRect rect = gid.getDisplayBounds();

Dimension dim = new Dimension (rect.getWidth(), rect.getHeight());

aspect = (float)rect.getWidth() / (float)rect.getHeight();

System.out.println("Aspect ratio is " + aspect);

QTImageProducer qtip = new QTImageProducer (gid, dim);



// From the QTImageProducer create a Java image for drawing

javaImage = Toolkit.getDefaultToolkit().createImage(qtip);

caught = true; //stops paint trying to draw a non existant image

repaint(); //calls paint () to display Java image on Java canvas

} catch (QTException ea) { //close down QT because there was a problem

System.out.println("Exception in capture menu");

ea.printStackTrace();

QTSession.close ();

}

}

});



//When the user closes the window, the window listener terminates the QT session,

//disposes of the frame and the program quits

addWindowListener(new WindowAdapter () {

public void windowClosing (WindowEvent e) {

QTSession.close();

dispose();

}

public void windowClosed(WindowEvent e) {

System.exit(0);

}

});

}



public void paint(Graphics g) {

// System.out.println("Paint");

if (caught) { //protect against trying to draw no image

System.out.println("Paint after caught");

int width = getSize().width;

int height = getSize().height;

g.drawImage(javaImage,20,50, (int)(aspect * 60.0) , 60 , null); //paint Java image

}

};

//use of public variables not normally encouraged

public Image javaImage;

public Movie m;

public boolean caught = false;

public Panel mp = new Panel();

public Panel IP = new Panel();

public GraphicsImporter gi = new GraphicsImporter (StdQTConstants.kQTFileTypePicture);

public GraphicsImporterDrawer gid = new GraphicsImporterDrawer (gi);

public float aspect = (float)16/(float)9;

}
#4

شكراً جزيلاً على الردود وأخص بالشكر أخي MKSoft على محاولته الرائعة

أريد أن أوضح أكثر حول الأكواد

أنا عندي كوديين مكتوبة بالجافا الكود الأول وهو الرئيسي MyPlayMovie وظيفته فتح ملف فيدو Quick Time ويقوم بإنشاء Control Buttons عليها حيث تعتبر Buttons هي

play و Stop و RR و FF و Capture

جميع الأزرار السابقة شغالة ماعدى Capture حيث الكود الخاص بـ Image Capture موجود على شكل كود ثاني منفصل بهيئة قائمة منسدلة

أنا أبغى أضع كود الخاص Image capture على هيئة Button في الكود الأول الرئيسي فقط

// MyPlayMovie الكود الأول (الرئيسي)

import java.awt.*;

import java.awt.event.*;

import quicktime.*;

import quicktime.io.*;

import quicktime.std.movies.*;

import quicktime.app.view.*;


public class MyPlayMovie extends Frame implements ActionListener, Errors{

Button revButton,

stopButton,

startButton,

fwdButton,

capButton;

Movie theMovie;


public static void main (String args[]) {

try {

QTSession.open();

MyPlayMovie pm = new MyPlayMovie("QT in Java");

pm.pack();

pm.show();

pm.toFront();

} catch (QTException e) {

e.printStackTrace();

QTSession.close ();

}

}

MyPlayMovie (String title) throws QTException { 

super (title);

// prompt the user to select a movie file

QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);


// open the file and make the movie from it

OpenMovieFile moviefile = OpenMovieFile.asRead(qtf);

Movie m = Movie.fromFile(moviefile);

theMovie = m;


// construct a movie controller from the movie 

//enable the keyboard so the user can interact with it

MovieController mc = new MovieController(m);

mc.setKeysEnabled (true);


// create and add a QTComponent and set qtc's movie controller

QTComponent qtc = QTFactory.makeQTComponent(mc);

Component c = qtc.asComponent();

//add((Component)qtc);

add (c, BorderLayout.CENTER);

Panel buttons = new Panel();

revButton = new Button("Back");

revButton.addActionListener (this);

stopButton = new Button ("Stop");

stopButton.addActionListener (this);

startButton = new Button ("Play");

startButton.addActionListener (this);

fwdButton = new Button ("Forward");

fwdButton.addActionListener (this);

capButton = new Button ("Capture");

capButton.addActionListener (this);

buttons.add (revButton);

buttons.add (stopButton);

buttons.add (startButton);

buttons.add (fwdButton);

buttons.add (capButton);

add (buttons, BorderLayout.SOUTH);

pack();

//user closes the window, listener terminates QT session, disposes of frame and program quits

addWindowListener(new WindowAdapter() { //an anonymnous inner class

public void windowClosing(WindowEvent we) { //overide method

QTSession.close();

dispose(); //dispose of window

}

public void windowClosed(WindowEvent we) {

System.exit(0); //quit the program

}

});

}

public void actionPerformed (ActionEvent e) {

try {

if (e.getSource() == revButton)

theMovie.setRate (theMovie.getRate() - 1.0f);

else if (e.getSource() == stopButton)

theMovie.stop();

else if (e.getSource() == startButton)

theMovie.start();

else if (e.getSource() == capButton)

ماذا أضع هنا

else if (e.getSource() == fwdButton)

theMovie.setRate (theMovie.getRate() + 1.0f);

} catch (QTException qte) {

qte.printStackTrace();

}

}

}

الكود السابق هو الكود الرئيسي الخاص بـالأزرار

الكود التالي هو كود capture

فقط أريد كيف أسحب الكود الثاني وأضعة في الكود الأول بشكل صحيح وبدون أخطاء

مع العلم أن الكود الثاني على هيئة قائمة

وأنا أريد وضعه على هيئة Button في الكود الأول

// MyImagePresenter الكود الثاني

//Captures an image from a movie as a PICT, converts it to look like a PICT file

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.io.IOException;

import quicktime.*;

import quicktime.io.*;

import quicktime.qd.*;

import quicktime.std.*;

import quicktime.std.movies.*;

import quicktime.std.movies.media.*;

import quicktime.app.view.*;

import quicktime.std.image.*;


public class MyImagePresenter extends Frame { 

public static void main (String args[]) {

try {

System.out.println("Image Capture from Movie to Java Images");

QTSession.open();

MyImagePresenter pm = new MyImagePresenter("Image Capture from Movie to Java Images");

pm.show();

pm.toFront();

} catch (QTException e) {

System.out.println("QT init problem");

e.printStackTrace();

QTSession.close ();

}

}


MyImagePresenter (String title) throws QTException {

super (title);


final Canvas mCanvas = new Canvas(); //get a Java canvas for the image

ip.setSize(450, 400);

ip.add(mCanvas);

add(ip, "West");


MenuBar menuBar = new MenuBar(); //get a menu

Menu captureMenu = new Menu ("Capture"); 

MenuItem nowMenuItem = new MenuItem ("Now"); 

captureMenu.add(nowMenuItem); 

menuBar.add (captureMenu);

this.setMenuBar (menuBar);


//prompt the user to select a movie file

QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);


//open the file and make the movie from it 

OpenMovieFile moviefile = OpenMovieFile.asRead(qtf);

m = Movie.fromFile(moviefile);


//construct a movie controller from the movie

MovieController mc = new MovieController(m);

mc.setKeysEnabled (true);


//create a QT Component so the movie controller has a place to draw

//add it to a panel, add the panel to the frame 

QTComponent qtc = QTFactory.makeQTComponent(mc);

mp.setSize(mc.getBounds().getWidth()+20, mc.getBounds().getHeight()+40);

mp.add((Component)qtc);

add(mp, "East");

//set the bounds of the Frame based on the dimensions of the movie

setBounds(0,0, mc.getBounds().getWidth() +300, mc.getBounds().getHeight() +40);


nowMenuItem.addActionListener (new ActionListener () {

public void actionPerformed(ActionEvent event) {

//this is where the image work is done

try {

System.out.println("Movie Time" + m.getTime());


Pict mpict = m.getPict(m.getTime()); //get PICT from current frame

//As there is no constructor to make an image from a PICT we have to 

// pretend we have a PICT file by adding 512 bytes header to PICT

byte[] newPictBytes = new byte [mpict.getSize() + 512];

mpict.copyToArray (0, newPictBytes, 512, newPictBytes.length - 512);

mpict = new Pict (newPictBytes);

//get a Dataref to the PICT - structure in movie toolbox

DataRef ref = new DataRef (mpict, StdQTConstants.kDataRefQTFileTypeTag, "PICT");


// make a graphicsImporterDrawer from the dataref to represent an image that is stored as a file 

// that can be read and drawn using QuickTime GraphicsImporter component

GraphicsImporterDrawer gid = new GraphicsImporterDrawer(ref);

//Create a QTImageProducer from the GraphicsImporterDrawer to produce the image for drawing

QDRect rect = gid.getDisplayBounds();

Dimension dim = new Dimension (rect.getWidth(), rect.getHeight());

aspect = (float)rect.getWidth() / (float)rect.getHeight();

System.out.println("Aspect ratio is " + aspect);

QTImageProducer qtip = new QTImageProducer (gid, dim);


// From the QTImageProducer create a Java image for drawing

javaImage = Toolkit.getDefaultToolkit().createImage(qtip);

caught = true; //stops paint trying to draw a non existant image

repaint(); //calls paint () to display Java image on Java canvas

} catch (QTException ea) { //close down QT because there was a problem

System.out.println("Exception in capture menu");

ea.printStackTrace();

QTSession.close ();

} 

}

});

//When the user closes the window, the window listener terminates the QT session,

//disposes of the frame and the program quits 

addWindowListener(new WindowAdapter () {

public void windowClosing (WindowEvent e) { 

QTSession.close();

dispose();

}

public void windowClosed(WindowEvent e) {

System.exit(0);

}

});

}

public void paint(Graphics g) { 

// System.out.println("Paint");

if (caught) { //protect against trying to draw no image

System.out.println("Paint after caught");

int width = getSize().width;

int height = getSize().height;

g.drawImage(javaImage,20,50, (int)(aspect * 60.0) , 60 , null); //paint Java image

}

};

//use of public variables not normally encouraged

public Image javaImage;

public Movie m;

public boolean caught = false;

public Panel mp = new Panel();

public Panel ip = new Panel();

public GraphicsImporter gi = new GraphicsImporter (StdQTConstants.kQTFileTypePicture);

public GraphicsImporterDrawer gid = new GraphicsImporterDrawer (gi);

public float aspect = (float)16/(float)9;

}
#5

هذا تعديل ارجوا ان يكون صحيحا ... حيث اني لم اقوم بتجريبه وذلك لاني لا امتلك packages لهذا المشرووع ...

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.io.IOException;



import quicktime.*;

import quicktime.io.*;

import quicktime.qd.*;

import quicktime.std.*;

import quicktime.std.movies.*;

import quicktime.std.movies.media.*;

import quicktime.app.view.*;

import quicktime.std.image.*;

public class MyPlayMovie extends Frame implements ActionListener, Errors
{

	Button revButton,
	stopButton,
	startButton,
	fwdButton,
	capButton;
	Movie theMovie;

	public Movie m;
	public float aspect = (float)16/(float)9;

	public static void main (String args[]) 
	{
		try 
		{
			QTSession.open();
			MyPlayMovie pm = new MyPlayMovie("QT in Java");
			pm.pack();
			pm.show();
			pm.toFront();
		} 
		catch (QTException e) 
		{
			e.printStackTrace();
			QTSession.close ();
		}
	}
	MyPlayMovie (String title) throws QTException 
	{
		super (title);
		QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);

		OpenMovieFile moviefile = OpenMovieFile.asRead(qtf);

		m = Movie.fromFile(moviefile);
		theMovie = m;

		MovieController mc = new MovieController(m);

		mc.setKeysEnabled (true);



		// create and add a QTComponent and set qtc's movie controller

		QTComponent qtc = QTFactory.makeQTComponent(mc);

		component c = qtc.asComponent();

		//add((Component)qtc);

		add (c, BorderLayout.CENTER);

		Panel buttons = new Panel();

		revButton = new Button("Back");

		revButton.addActionListener (this);

		stopButton = new Button ("Stop");

		stopButton.addActionListener (this);

		startButton = new Button ("Play");

		startButton.addActionListener (this);

		fwdButton = new Button ("Forward");

		fwdButton.addActionListener (this);

		capButton = new Button ("Capture");

		capButton.addActionListener (this);

		buttons.add (revButton);

		buttons.add (stopButton);

		buttons.add (startButton);

		buttons.add (fwdButton);

		buttons.add (capButton);

		add (buttons, BorderLayout.SOUTH);

		pack();

		addWindowListener(new WindowAdapter() 
		{ //an anonymnous inner class

			public void windowClosing(WindowEvent we) 
			{ //overide Method

				QTSession.close();
				dispose(); //dispose of window

			}

			public void windowClosed(WindowEvent we) 
			{

				System.exit(0); //quit the program

			}

		});

	}

	public void actionPerformed (ActionEvent e) 
	{

		try 
		{

			if (e.getSource() == revButton)

			theMovie.setRate (theMovie.getRate() - 1.0f);

			else if (e.getSource() == stopButton)

			theMovie.stop();

			else if (e.getSource() == startButton)

			theMovie.start();

			else if (e.getSource() == capButton)
			{
			/*	MyImagePresenter pm = new MyImagePresenter("Image Capture from Movie to Java Images");

				pm.show();

				pm.toFront();*/

				try 
				{

					System.out.println("Movie Time" + m.getTime());

					Pict mpict = m.getPict(m.getTime()); //get PICT from current frame

					byte[] newPictBytes = new byte [mpict.getSize() + 512];

					mpict.copyToArray (0, newPictBytes, 512, newPictBytes.length - 512);

					mpict = new Pict (newPictBytes);

					DataRef ref = new DataRef (mpict, StdQTConstants.kDataRefQTFileTypeTag, "PICT");

					GraphicsImporterDrawer gid = new GraphicsImporterDrawer(ref);

					QDRect rect = gid.getDisplayBounds();

					Dimension dim = new Dimension (rect.getWidth(), rect.getHeight());

					aspect = (float)rect.getWidth() / (float)rect.getHeight();

					System.out.println("Aspect ratio is " + aspect);

					QTImageProducer qtip = new QTImageProducer (gid, dim);

					javaImage = Toolkit.getDefaultToolkit().createImage(qtip);

					caught = true; //stops paint trying to draw a non existant image

					repaint(); //calls paint () to display Java image on Java canvas

				} 
				catch (QTException ea)
				{ 
					System.out.println("Exception in capture menu");

					ea.printStackTrace();

					QTSession.close ();

				}

			}


			else if (e.getSource() == fwdButton)

			theMovie.setRate (theMovie.getRate() + 1.0f);

		} 
		catch (QTException qte) 
		{

			qte.printStackTrace();

		}

	}

}
//////////////////////////////

مواضيع مشابهة