Print Friendly and PDF

Program:

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.media.*;
import java.awt.image.*;
import javax.imageio.*;

public class Media extends JFrame{
 private Player player;
 private File file;
JFrame frame1 = new JFrame();
JFrame frame2 = new JFrame();
JPanel p=new JPanel();int i=0;
 public Media(){super( "2EMP" );
JMenu m1 = new JMenu("Media");
JMenuItem i1=m1.add(new JMenuItem("Open File"));
m1.add(new JSeparator());
JMenuItem i2=m1.add(new JMenuItem("Playlist"));
m1.add(new JSeparator());
JMenuItem i3=m1.add(new JMenuItem("Quit"));
JMenu m2 = new JMenu("View");


 JMenuItem i4=m2.add(new JMenuItem("Small Screen"));
m2.add(new JSeparator());
JMenuItem i5=m2.add(new JMenuItem("Full Screen"));
m2.add(new JSeparator());
JMenuItem i6=m2.add(new JMenuItem(""));
p.setLayout (new BoxLayout(p, BoxLayout.Y_AXIS));
JMenu m3 = new JMenu("Info.");
JMenuItem i7=m3.add(new JMenuItem("Help"));
m3.add(new JSeparator());
JMenuItem i8=m3.add(new JMenuItem("About"));
frame2.setTitle("Playlist");
JMenuBar bar = new JMenuBar();


bar.add(m1);
 bar.add(m2);
 bar.add(m3);
JFrame frame = new JFrame();
setJMenuBar(bar);
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
i1.addActionListener( new ActionListener()
{
 public void actionPerformed( ActionEvent e )



{
openFile();
createPlayer();

}

}
 );
i2.addActionListener( new ActionListener()
{
 public void actionPerformed( ActionEvent e )
{
openFile();
 playlist();
}

}
 );
i3.addActionListener( new ActionListener()
{
 public void actionPerformed( ActionEvent e )
{


System.exit(0);
}

}
 );
i4.addActionListener( new ActionListener()
{
 public void actionPerformed( ActionEvent e )
{
setLocation(0,0);
setSize(300,300);
 }

}
 );
i5.addActionListener( new ActionListener()
{ 
public void actionPerformed( ActionEvent e )
{
setLocation(0,0);
setSize(1000,700);
}

}
 );
i6.addActionListener( new ActionListener()
{ 
public void actionPerformed( ActionEvent e )
{
snap();
 }

}
 );
i7.addActionListener( new ActionListener()
{
 public void actionPerformed( ActionEvent e )
{
JOptionPane.showMessageDialog( null, " Java Media Player \n\nTo increase or decerese the volume: right click on the sound icon\nTo increase decerese  the speed of player: right click on the next icon\nTo view the properties of media files: leftclick on icon", "About",JOptionPane.PLAIN_MESSAGE );

}

}
 );
i8.addActionListener( new ActionListener()
{
 public void actionPerformed( ActionEvent e )
{
JOptionPane.showMessageDialog( null, "THIS APPLICATION IS THE PROPERTY OF EVANS NANA ADU AND EGBENU EDEM WELBECK. ","About",JOptionPane.PLAIN_MESSAGE );

}

}
 );
}
  private void snap()
{
try
{
Robot robot = new Robot();
BufferedImage [] bi=new BufferedImage[10];


bi[i]=robot.createScreenCapture(new
Rectangle((Toolkit.getDefaultToolkit().getScreenSize())));
ImageIO.write(bi[i], "jpg", new File("d:/imageTest"+i+".jpg"));i++;
}
 catch (AWTException e1)



 {
e1.printStackTrace();
}
 catch (IOException e1)
{
e1.printStackTrace();
}

}
  private void openFile()
{
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY );
int result = fileChooser.showOpenDialog( this );
if ( result == JFileChooser.CANCEL_OPTION )
file = null;
else
file = fileChooser.getSelectedFile();
}
  private void playlist()
{
final JButton l1, l2,l3;
l1 = new JButton(file.toString());
if (p!=null)

frame2.remove(p);
 p.add(l1);
l1.addActionListener(new ActionListener()


{
 public void actionPerformed( ActionEvent e )
{
file=new File(l1.getText());


createPlayer();
}

}
 );
 p.add(Box.createVerticalGlue());
frame2.add(p);
frame2.pack();
frame2.setVisible(true);
}
  private void createPlayer()

{
if ( file == null )
return;
removePreviousPlayer();
try

{ 
player = Manager.createPlayer( file.toURL() );
 player.addControllerListener( new EventHandler() );
 player.start();
}
 catch ( Exception e )
{


 JOptionPane.showMessageDialog( this, "Invalid file or location", "Error loadingfile",JOptionPane.ERROR_MESSAGE );
}

}
  private void removePreviousPlayer()
{
if ( player == null )
return;




Component visual = player.getVisualComponent();
Component control = player.getControlPanelComponent();
Container c = getContentPane();
if ( visual != null )
c.remove( visual );
if ( control != null )
c.remove( control );
 player.close();
 }
  public static void main(String args[])
{
Media app = new Media();
app.addWindowListener( new WindowAdapter()
{
 public void windowClosing( WindowEvent e )
{
System.exit(0);
}
}
 );
}
  private class EventHandler implements ControllerListener 
{
 public void controllerUpdate (ControllerEvent e)
{
if ( e instanceof RealizeCompleteEvent )
{
Container c = getContentPane();
Component visualComponent =player.getVisualComponent();
if ( visualComponent != null )
c.add( visualComponent, BorderLayout.CENTER );
Component controlsComponent =player.getControlPanelComponent();
if ( controlsComponent != null )
c.add( controlsComponent, BorderLayout.SOUTH );


c.doLayout();
}

}

}

}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: