You are on page 1of 73

INDEX Sr No.

A) Create an Applet or swing based application with play, pause and stop options for playing an Audio file. B) Create an Applet or a swing based application for playing a Video file. Create an applet or swing based application to play separate streams (video and audio) in synchronization. Write a program based on applet or swing based application which will display the list of all the alphabets in a combo. Write a program to mix two different audio stream. Write a program to teach counting of objects (With the help of images and audio) Write a program to design a calculator with audio for basic operations like addition, subtraction, multiplication and division (javax.speech package can be used). Create an animated applet or frame by Using some image files. Write a program to read a text file using Free TTS Package. Using Media tracker, create a slide show. Using Media tracker, create a movie clip.
Multimedia Systems

Topic

Date

Sign

2 3

4 5 6

7 8 9 10

M.Sc. IT Part-II

Practical No:1(A) Code: AudioProgram.java importjavax.swing.*; importjava.awt.*; importjava.awt.event.*; importjava.applet.*; //<applet code="AudioProgram" width=200 height=50></applet> public class AudioProgram extends JApplet implements ActionListener { AudioClip ac; JButton b1,b2,b3; public void init() { Container con=getContentPane(); con.setLayout(new FlowLayout()); b1=new JButton("Play"); con.add(b1); b1.addActionListener(this);

M.Sc. IT Part-II

Multimedia Systems

b2=new JButton("Loop"); con.add(b2); b2.addActionListener(this); b3=new JButton("Stop"); con.add(b3); b3.addActionListener(this); ac=getAudioClip(getDocumentBase(),"notify.wav"); } public void actionPerformed(ActionEventev) { if(ev.getSource()==b1) { ac.play(); } if(ev.getSource()==b2) { ac.loop(); } if(ev.getSource()==b3) { ac.stop(); }}}

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:1(B) CODE : VideoPro.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; import java.io.*; import javax.media.*; public class VideoPro extends JFrame { Player player; File f; Container con; public static void main(String[] args)throws IOException { VideoProvp=new VideoPro(); } VideoPro() {

M.Sc. IT Part-II

Multimedia Systems

con=getContentPane(); con.setLayout(new BorderLayout()); setSize(300,300); try { f=new File("camera.mpg"); URL url=f.toURL(); if(player!=null) { player.stop(); } player =Manager.createPlayer(url); ControllerListener listener=new ControllerAdapter() { public void realizeComplete(RealizeCompleteEvent eve) { Component vc=player.getVisualComponent(); if(vc!=null) { con.add(vc,BorderLayout.CENTER); } else
M.Sc. IT Part-II Multimedia Systems

{ con.remove(vc); con.validate(); } Component cpc=player.getControlPanelComponent(); if(cpc!=null) { con.add(cpc,BorderLayout.SOUTH); } else { con.remove(cpc); con.validate(); } pack(); setTitle("VideoPlayer: "+f.getName()); } }; this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) {
M.Sc. IT Part-II

System.exit(0); }
Multimedia Systems

}); player.addControllerListener(listener); player.start(); } catch(Exception e) { System.out.println(e); }

setVisible(true); } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:2 CODE : AudioVideo.java import java.io.*; importjavax.swing.*; importjavax.media.*; importjava.awt.*; importjava.awt.event.*; import java.net.*; classAudioVideo extends JFrame implements Runnable { String name; Thread t; Player player; Component center,south; AudioVideo(String threadname) { name = threadname; t = new Thread(this, name); t.start(); } public void run()

M.Sc. IT Part-II

Multimedia Systems

{ try { if(name == "One") { File f = new File("camera.mpg"); try { load(f); }

catch (Exception e) { System.out.println(e); }

pack(); setVisible(true); Thread.sleep(1000); } if(name == "Two") { File f1 = new File("start.wav"); try { load(f1); }

catch (Exception e) { System.out.println(e);

M.Sc. IT Part-II

Multimedia Systems

} pack(); setVisible(true); Thread.sleep(1000); } } catch (InterruptedException e) { System.out.println(name + "Interrupted"); } } public void load(final File file) throws Exception { URL url = file.toURL(); final Container contentPane =getContentPane(); if (player != null) { player.stop(); } player = Manager.createPlayer(url); ControllerListener listener = new ControllerAdapter() {

M.Sc. IT Part-II

Multimedia Systems

public void realizeComplete(RealizeCompleteEvent event) { Component vc = player.getVisualComponent(); if (vc != null) { contentPane.add(vc,BorderLayout.CENTER); center = vc; } else { if (center != null) { contentPane.remove(center); contentPane.validate(); } } Component cpc = player.getControlPanelComponent(); if (cpc != null) { contentPane.add(cpc,BorderLayout.SOUTH); south = cpc; }

M.Sc. IT Part-II

Multimedia Systems

else { if (south != null) { contentPane.remove(south); contentPane.validate(); } } pack(); setTitle("Video & Audio Player : " +file.getName()); } }; player.addControllerListener(listener); player.start(); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); }

M.Sc. IT Part-II

Multimedia Systems

} classVideoAudioMix { public static void main(String args[]) { newAudioVideo("One"); newAudioVideo("Two"); try { Thread.sleep(10000);}

catch (InterruptedException e) { System.out.println("Main thread Interrupted"); } } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:3 CODE : ImgAud.java import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.applet.*;

//<applet code="ImgAud" width=300 height=300></applet> public class ImgAud extends JApplet implements ItemListener { JComboBox jcb; private JLabel jlbl; //private String alpha[]={"1","2","3","4"}; private String alpha[]={"A","B","C","D"};//FOR KARU private Icon img[]=new Icon[4]; private AudioClip ac[]=new AudioClip[4]; public void init() { Container con=getContentPane(); con.setLayout(new FlowLayout());

M.Sc. IT Part-II

Multimedia Systems

jcb=new JComboBox(alpha);

jcb.addItemListener(this);

for(int i=0;i<4;i++) { img[i]=new ImageIcon(alpha[i]+".jpg"); ac[i]=getAudioClip(getDocumentBase(),alpha[i]+".wav"); } ac[0].play(); jlbl=new JLabel(img[0]); con.add(jlbl); con.add(jcb); } public void itemStateChanged(ItemEvent e) { jlbl.setIcon(img[jcb.getSelectedIndex()]); ac[jcb.getSelectedIndex()].play(); } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:4 CODE : mix .java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; /*<applet code="mix" width=200 height=100></applet>*/ public class mix extends JApplet implements Runnable { AudioClip ac1,ac2; Thread t1,t2; public void init() { ac1=getAudioClip(getDocumentBase(),"notify.wav"); ac2=getAudioClip(getDocumentBase(),"start.wav"); t1=new Thread(this); t1.start(); System.out.println("t1 started!!!"); t2=new Thread(this); t2.start();

M.Sc. IT Part-II

Multimedia Systems

System.out.println("t2 started!!!");

} public void run() { System.out.println("Inside run!!!"); ac1.play(); ac2.play(); } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:5 CODE : countShapes.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; /*<applet code="countShapes" width=500 height=500></applet>*/ public class countShapes extends JApplet implements ActionListener { Container cont; JPanel p; JLabellblCount; JButtonbtCircle,btSquare,btRect,btTria; booleanblnCircle,blnSquare,blnRect,blnTria; int count=0; String shape=""; AudioClipcircleClip,squareClip,rectClip,triaClip; public void init() { cont=getContentPane();
M.Sc. IT Part-II Multimedia Systems

circleClip=getAudioClip(getCodeBase(),"circle.wav"); squareClip=getAudioClip(getCodeBase(),"square.wav"); rectClip=getAudioClip(getCodeBase(),"rect.wav"); triaClip=getAudioClip(getCodeBase(),"tria.wav");

lblCount=new JLabel("Shape Count :0",JLabel.CENTER); lblCount.setFont(new Font("Arial",Font.BOLD,18)); cont.add(lblCount,BorderLayout.NORTH);

btCircle=new JButton("circle"); btSquare=new JButton("square"); btRect=new JButton("rectangle"); btTria=new JButton("triangle");

btCircle.addActionListener(this); btSquare.addActionListener(this); btRect.addActionListener(this); btTria.addActionListener(this);

p=new JPanel(); p.add(btCircle); p.add(btSquare);

M.Sc. IT Part-II

Multimedia Systems

p.add(btRect); p.add(btTria); cont.add(p,BorderLayout.SOUTH); } public void actionPerformed(ActionEventae) { if(ae.getSource()==btCircle) { if(blnSquare==true||blnRect==true||blnTria==true) { blnSquare=false; blnRect=false; blnTria=false; count=0; } blnCircle=true; shape="CIRCLE"; count++; lblCount.setText(shape+" count : "+count); repaint(); circleClip.play(); }

M.Sc. IT Part-II

Multimedia Systems

if(ae.getSource()==btSquare) { if(blnCircle==true||blnRect==true||blnTria==true) { blnCircle=false; blnRect=false; blnTria=false; count=0; } blnSquare=true; shape="SQUARE"; count++; lblCount.setText(shape+" count : "+count); repaint(); squareClip.play(); } if(ae.getSource()==btRect) { if(blnSquare==true||blnCircle==true||blnTria==true) { blnSquare=false; blnCircle=false;

M.Sc. IT Part-II

Multimedia Systems

blnTria=false; count=0; } blnRect=true; shape="RECTANGLE"; count++; lblCount.setText(shape+" count : "+count); repaint(); rectClip.play(); } if(ae.getSource()==btTria) { if(blnSquare==true||blnRect==true||blnCircle==true) { blnSquare=false; blnRect=false; blnCircle=false; count=0; } blnTria=true; shape="TRIANGLE"; count++;

M.Sc. IT Part-II

Multimedia Systems

lblCount.setText(shape+" count : "+count); repaint(); triaClip.play(); } } public void paint(Graphics g) { cont.paint(cont.getGraphics()); int x=10, y=30, w=30, h=30; if(shape.equals("CIRCLE") || shape.equals("SQUARE")) { for(inti=0;i<count;i++) { if(y>=p.getY()-30) { JOptionPane.showMessageDialog(this,"Exceeding the limit of area for drawing.\n\nChoose different shape."); shape=""; count=0; break; } else {
M.Sc. IT Part-II Multimedia Systems

if(shape.equals("CIRCLE")) g.drawOval(x,y,w,h); else g.drawRect(x,y,w,h); x+=40; if(x>=getWidth()-30) { x=10; y+=40; } } } } x=10;y=30;w=50;h=30; if(shape.equals("RECTANGLE")) { for(inti=0;i<count;i++) { if(y>=p.getY()-30) { JOptionPane.showMessageDialog(this,"Exceeding the limit of area for drawing.\n\nChoose different shape."); shape="";
M.Sc. IT Part-II Multimedia Systems

count=0; lblCount.setText("Shape Count : 0"); break; } else { g.drawRect(x,y,w,h); x+=60; if(x>=getWidth()-60) { x=10; y+=40; } } } } if(shape.equals("TRIANGLE")) { intwp=60,hp=60,xp=10,yp=30; for(inti=0;i<count;i++) { if(yp+hp>=p.getY())

M.Sc. IT Part-II

Multimedia Systems

{ JOptionPane.showMessageDialog(this,"Exceeding the limit of area for drawing.\n\nChoose different shape."); shape=""; count=0; lblCount.setText("Shape Count : 0"); break; } else { int[] xpa={xp+(wp/2),xp,(xp+wp)}; int[] ypa={yp,yp+hp,yp+hp}; g.drawPolygon(xpa,ypa,3); xp+=70; if(xp>=getWidth()-wp) { xp=10; yp+=70; } } } }}}

M.Sc. IT Part-II

Multimedia Systems

OUTPUT:

M.Sc. IT Part-II

Multimedia Systems

Practical No:6

CODE : Calculator.java import java.awt.*; import java.applet.*; import java.io.*; import java.awt.event.*; import javax.swing.*;

/* <applet code = Calculator width=250 height=200 ></applet> */

public class Calculator extends Applet implements ActionListener { Panel p1 = new Panel(); Panel p2 = new Panel(); TextField text; Button equalto, one, two, three, four, five, six, seven, eight, nine, zero, c, plus, minus, multi, divide; String sText1, sText2,sOperator,str,s; double num1, num2;
M.Sc. IT Part-II Multimedia Systems

booleanisFixReg; AudioClip ac;

public Calculator() { initProperty();

text = new TextField("",12); text.setEditable(false); text.setBackground(Color.white);

p1.add(text);

seven=new Button("7"); eight=new Button("8"); nine=new Button("9"); plus=new Button("+");

four=new Button("4"); five=new Button("5"); six=new Button("6"); minus=new Button("-");

M.Sc. IT Part-II

Multimedia Systems

one=new Button("1"); two=new Button("2"); three=new Button("3"); multi=new Button("*");

c=new Button("C"); zero=new Button("0"); equalto=new Button("="); divide=new Button("/");

p2.add(seven); p2.add(eight); p2.add(nine); p2.add(plus);

p2.add(four); p2.add(five); p2.add(six); p2.add(minus);

p2.add(one);

M.Sc. IT Part-II

Multimedia Systems

p2.add(two); p2.add(three); p2.add(multi);

p2.add(c); p2.add(zero); p2.add(equalto); p2.add(divide); seven.addActionListener(this); eight.addActionListener(this); nine.addActionListener(this); plus.addActionListener(this);

four.addActionListener(this); five.addActionListener(this); six.addActionListener(this); minus.addActionListener(this);

one.addActionListener(this); two.addActionListener(this); three.addActionListener(this); multi.addActionListener(this);

M.Sc. IT Part-II

Multimedia Systems

c.addActionListener(this); zero.addActionListener(this); equalto.addActionListener(this); divide.addActionListener(this);

num1 = 0.0d; num2 = 0.0d; sOperator = ""; text.setText("0"); isFixReg = false; }

private void initProperty() { setLayout(new BorderLayout()); add(p1,BorderLayout.NORTH); add(p2,BorderLayout.CENTER); p2.setLayout(new GridLayout(4,4)); setSize(150,200); setVisible(true); }

M.Sc. IT Part-II

Multimedia Systems

public void actionPerformed(ActionEvent e) { str = e.getActionCommand(); if (str.equals("C")) { ac = getAudioClip(getCodeBase(),"c.wav"); ac.play(); num1 = 0.0d; num2 = 0.0d; sOperator = ""; text.setText("0"); isFixReg = true; } else if ((str.equals("0")) | (str.equals("1")) | (str.equals("2"))| (str.equals("3")) | (str.equals("4")) | (str.equals("5"))| (str.equals("6")) | (str.equals("7")) | (str.equals("8"))| (str.equals("9"))) { if (isFixReg) sText2 = (String) str; else sText2 = text.getText() + str; text.setText(sText2); isFixReg = false;
M.Sc. IT Part-II Multimedia Systems

if(str.equals("0")) { ac= getAudioClip(getCodeBase(),"0.wav"); ac.play(); } else if(str.equals("1")) { ac= getAudioClip(getCodeBase(),"1.wav"); ac.play(); } else if(str.equals("2")) { ac= getAudioClip(getCodeBase(),"2.wav"); ac.play(); } else if(str.equals("3")) { ac= getAudioClip(getCodeBase(),"3.wav"); ac.play(); } else if(str.equals("4"))

M.Sc. IT Part-II

Multimedia Systems

{ ac= getAudioClip(getCodeBase(),"4.wav"); ac.play(); } else if(str.equals("5")) { ac= getAudioClip(getCodeBase(),"5.wav"); ac.play(); } else if(str.equals("6")) { ac= getAudioClip(getCodeBase(),"6.wav"); ac.play(); } else if(str.equals("7")) { ac= getAudioClip(getCodeBase(),"7.wav"); ac.play(); } else if(str.equals("8")) { ac= getAudioClip(getCodeBase(),"8.wav");

M.Sc. IT Part-II

Multimedia Systems

ac.play(); } else if(str.equals("9")) { ac= getAudioClip(getCodeBase(),"9.wav"); ac.play(); } } else if ((str.equals("+")) | (str.equals("-"))| (str.equals("*")) | (str.equals("/")) | (str.equals("="))) { if(str.equals("+")) { ac= getAudioClip(getCodeBase(),"plus.wav"); ac.play(); } else if(str.equals("-")) { ac= getAudioClip(getCodeBase(),"minus.wav"); ac.play(); } else if(str.equals("*")) {
M.Sc. IT Part-II Multimedia Systems

ac= getAudioClip(getCodeBase(),"multiply.wav"); ac.play(); } else if(str.equals("/")) { ac= getAudioClip(getCodeBase(),"divide.wav"); ac.play(); } else if(str.equals("=")) { ac= getAudioClip(getCodeBase(),"equal.wav"); ac.play(); } sText1 = text.getText(); num2 = (Double.valueOf(sText1)).doubleValue(); num1 = Calculation(sOperator, num1, num2); Double dTemp = new Double(num1); sText2 = dTemp.toString(); text.setText(sText2); sOperator = (String) str; isFixReg = true; }

M.Sc. IT Part-II

Multimedia Systems

} private double Calculation(String sOperator, double num1, double num2) { if ("+".equals(sOperator)) num1 = num1 + num2; else if ("-".equals(sOperator)) num1 = num1 - num2; else if ("*".equals(sOperator)) num1 = num1 * num2; else if ("/".equals(sOperator)) num1 = num1 / num2; else num1 = num2; return num1; } public void paint (Graphics g) { g.drawString(s,6,100); } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:7 CODE : Animation.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; /*<applet code=Animation width=200 height=150></applet>*/ public class Animation extends JApplet { //ImageIconimg; Image img1; //JLabellblImg; //Icon icn; Thread tAni; inti=0; public void init() { try {

M.Sc. IT Part-II

Multimedia Systems

setLayout(null); Runnable r=new Runnable() { public void run() { try { while(true) { if(i<=45) { img1=Toolkit.getDefaultToolkit().getImage(i+".gif"); i++; if(i==46) //{ i=0; tAni.sleep(300); repaint(); //} } } }

M.Sc. IT Part-II

Multimedia Systems

catch(Exception e) { System.out.println("in runnable "+e); } } }; tAni=new Thread(r); tAni.start(); } catch(Exception e) { System.out.println("in init "+e); } } public void stop() { } public void paint(Graphics g) { try { super.paint(g);

M.Sc. IT Part-II

Multimedia Systems

g.drawImage(img1,50,50,this); } catch(Exception e) { System.out.println("in paint "+e); } } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:7(B) CODE : Animation.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; /*<applet code=Animation width=200 height=150></applet>*/ public class Animation extends JApplet { //ImageIconimg; Image img1; //JLabellblImg; //Icon icn; Thread tAni; inti=0; public void init() { try { setLayout(null);

M.Sc. IT Part-II

Multimedia Systems

Runnable r=new Runnable() { public void run() { try { while(true) { if(i<=5) { img1=Toolkit.getDefaultToolkit().getImage(i+".gif"); i++; if(i==4) //{ i=0; tAni.sleep(300); repaint(); //} } } } catch(Exception e)

M.Sc. IT Part-II

Multimedia Systems

{ System.out.println("in runnable "+e); } } }; tAni=new Thread(r); tAni.start(); } catch(Exception e) { System.out.println("in init "+e); } } public void stop() { } public void paint(Graphics g) { try { super.paint(g); g.drawImage(img1,50,50,this);

M.Sc. IT Part-II

Multimedia Systems

} catch(Exception e) { System.out.println("in paint "+e); } } }

OUTPUT:

M.Sc. IT Part-II

Multimedia Systems

M.Sc. IT Part-II

Multimedia Systems

Practical No:8 CODE : readTextFile1.java

importcom.sun.speech.freetts.Voice; importcom.sun.speech.freetts.VoiceManager; importcom.sun.speech.freetts.audio.JavaClipAudioPlayer; import java.io.*;

public class readTextFile1 { public static void main(String[] args) { FileInputStream fin=null; String fileName,strContents="";

VoiceManagervoiceManager = VoiceManager.getInstance(); Voice v = voiceManager.getVoice("kevin16");

try { fin=new FileInputStream("t1.txt");

M.Sc. IT Part-II

Multimedia Systems

System.out.println("\nNow Speaking..."); v.allocate(); v.speak(fin); v.deallocate();

fin.close();

System.out.println("\nOver Speaking..."); } catch(Exception e) { System.out.println("Exception occured : "+e.getMessage()); } } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT : t1.txt

M.Sc. IT Part-II

Multimedia Systems

Practical No:9 CODE : slideShow.java import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*;

/*<applet code="slideShow" width=350 height=400></applet>*/

public class slideShow extends JApplet implements ActionListener { Container con; int h; changeSlide change; MediaTracker tracker; Image[] img = new Image[13]; intcurrent_img=-1, tracked=0, stoppedOnImage; booleanstopFlag, blnDoNotRepaint; blnShowOn=true, blnNext, blnPrev,

JButtonbtNext, btPrev, btStart, btStop; JPanel p;


M.Sc. IT Part-II Multimedia Systems

public void init() { con = getContentPane(); con.setLayout(new BorderLayout()); p = new JPanel(); btNext = new JButton("Next"); btPrev = new JButton("Previous"); btStart = new JButton("Start"); btStop = new JButton("Stop");

btNext.addActionListener(this); btPrev.addActionListener(this); btStart.addActionListener(this); btStop.addActionListener(this);

p.add(btNext); p.add(btPrev); p.add(btStart); p.add(btStop); con.add(p,BorderLayout.NORTH); tracker = new MediaTracker(this); for(inti=0;i<13;i++)

M.Sc. IT Part-II

Multimedia Systems

{ img[i] = getImage(getCodeBase(),i+".jpg"); tracker.addImage(img[i],tracked); tracked++; } change = new changeSlide(this); } public void actionPerformed(ActionEventae) { if(ae.getSource()==btStop) { showStatus("Stopped"); change.t.suspend(); blnShowOn=false; } if(ae.getSource()==btStart) { change.t.resume(); showStatus("Started"); blnShowOn=true; } if(ae.getSource()==btNext)

M.Sc. IT Part-II

Multimedia Systems

{ change.t.suspend(); blnNext=true; nextPrevSlide ns = new nextPrevSlide(this); } if(ae.getSource()==btPrev) { System.out.println(current_img); blnPrev=true; nextPrevSlide ns = new nextPrevSlide(this); }} public void paint(Graphics g) { Graphics ge = p.getGraphics(); p.paint(ge); if(blnShowOn == false) g.drawImage(img[stoppedOnImage],0,40,null); if(blnShowOn) { intdoneCount=0; intcurrentlyLoading=0;

M.Sc. IT Part-II

Multimedia Systems

for(inti=0;i<tracked;i++) { if(tracker.checkID(i,true)==true) { doneCount++; currentlyLoading=i; showStatus("Total " +doneCount+ "Images Loaded, Now Loading...."+currentlyLoading+".jpg image."); } else { showStatus("Total "+doneCount +" Images Loaded, Now Loading...."+currentlyLoading+".jpg image."); } } if(doneCount == tracked) { showStatus("All Images Loaded.."); Image i1 = img[current_img]; g.drawImage(i1,0,40,null); showStatus("Currently showing : "+current_img+".jpg"); stoppedOnImage=current_img; }
M.Sc. IT Part-II Multimedia Systems

else { showStatus("Total "+doneCount+" Images Loaded, Now Loading...."+currentlyLoading+".jpg image."); } } if(blnDoNotRepaint == true) change.t.resume(); } public void start() { stopFlag=false; }

public void stop() { stopFlag = true; } }

classchangeSlide implements Runnable { Thread t;


M.Sc. IT Part-II Multimedia Systems

slideShow s; changeSlide(slideShowss) { s=ss; t=new Thread(this); t.start(); }

public void run() { if(s.blnShowOn) { while(true) { if(!s.blnDoNotRepaint) s.repaint();

try { Thread.sleep(3000); } catch(InterruptedException e)

M.Sc. IT Part-II

Multimedia Systems

{ } s.current_img++; if(s.current_img>s.tracked) s.current_img=0; if(s.blnDoNotRepaint) { try { Thread.sleep(3000); } catch(InterruptedException e) { } s.blnDoNotRepaint=false; } } } } } classnextPrevSlide implements Runnable {

M.Sc. IT Part-II

Multimedia Systems

Thread t; slideShow s; nextPrevSlide(slideShowss) { s=ss; t=new Thread(this); t.start(); }

public void run() { booleanblnDecremented = false; if(s.blnPrev) { if(s.current_img==0) { s.current_img=10; s.stoppedOnImage=s.current_img; blnDecremented=true; } if(s.current_img>=1 && !blnDecremented) {

M.Sc. IT Part-II

Multimedia Systems

s.current_img=s.current_img-1; s.stoppedOnImage=s.current_img; blnDecremented=false; } s.blnPrev=false; } if(s.blnNext) { if(s.current_img>=10) { s.current_img=0; s.stoppedOnImage=s.current_img; } else { s.current_img=s.current_img+1; s.stoppedOnImage=s.current_img; } s.blnNext=false; } s.blnDoNotRepaint=true; s.repaint();

M.Sc. IT Part-II

Multimedia Systems

t.stop(); } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

Practical No:10 CODE : movieClip.java import java.awt.*; import javax.swing.*; /* <applet code="movieClip" width=500 height=500> </applet> */ public class movieClip extends JApplet implements Runnable { Container cont; Thread t; int imgCount=1; int totalImages=20; JLabel l; MediaTracker tracker; int tracked=1; public void init() { cont=getContentPane(); cont.setBackground(Color.black); l=new JLabel(new ImageIcon(imgCount+".jpg")); cont.add(l,BorderLayout.CENTER); tracker=new MediaTracker(this); for(int i=1;i<=totalImages;i++) { tracker.addImage((new ImageIcon(i+".jpg")).getImage(),tracked);
M.Sc. IT Part-II Multimedia Systems

tracked++; } } public void start() { t=new Thread(this); t.start(); } public void run() { String loaded=""; int donecount=0; while(true) { for(int i=1;i<=tracked;i++) { if(tracker.checkID(i,true)) { donecount++; loaded+=i+".jpg, "; } } System.out.println("donecount : "+donecount); System.out.println("Tracked : "+tracked); if(donecount==tracked) { if(imgCount<totalImages) { imgCount++; l.setText(null); l.setIcon(new ImageIcon(imgCount+".jpg"));
M.Sc. IT Part-II Multimedia Systems

} else if(imgCount==totalImages) { l.setText(null); l.setIcon(new ImageIcon(imgCount+".jpg")); imgCount=0; } } else { l.setIcon(null); l.setText("Loaded Images are : "+loaded); } donecount=0; loaded=""; try { Thread.sleep(100); }catch(Exception e){} } } }

M.Sc. IT Part-II

Multimedia Systems

OUTPUT :

M.Sc. IT Part-II

Multimedia Systems

You might also like