⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mediaplayer.java

📁 java播放器 java播放器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * MediaPlayer.java
 *
 * Created on 2004年1月23日, 上午12:47
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package media;

/**
 *
 * @author zhongweijian
 */
/*
 * Main.java
 *
 * Created on 2004年1月23日, 上午12:38
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.*;
import java.io.*;
import java.util.*;//为了导入Vector
import com.sun.media.ui.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
//import com.sun.java.swing.plaf.windows.*;

public class MediaPlayer extends JFrame implements ActionListener,Runnable
{
	
	
	
	 private JList             list;//播放清单
     private JScrollPane       scroll;//使播放清单具有滚动功能
     private ListValues        listWriteFile;//用于向文件中读取对象
     private ObjectInputStream input;//对象输入流
     private ObjectOutputStream output;//对象输出流
    
    
     private Vector            fileName,dirName,numList;
     private String            files,dir;
     private int               index;//曲目指针
     private Properties        prop;//获得系统属性
     private int               indexForDel;//标志要删除的列表项目的索引
     private ButtonGroup       buttonGroup;//控制按钮组
     private JRadioButtonMenuItem[]    buttonValues;
     private String[]          content={"随机播放","顺序播放","单曲循环"};
    
     private JPopupMenu        popupMenu;//鼠标右键弹出菜单
     private JMenuItem         del,delAll,reName;      //弹出菜单显示的菜单项,包括删除,全部删除和重命名
    
    
    
     private DialogDemo        dialog1;
	 private JMenuBar          bar;//菜单条
	 private JMenu             fileMenu,choiceMenu,voiceMenu,helpMenu;//the name of bar
	 private JMenuItem         openItem,openDirItem,closeItem,about,info,voicehigh,voicelow;//the name of menu
	 private JCheckBoxMenuItem onTop;
	 private boolean           top=false,loop;//设定窗口是否在最前面
	 private Player            player;//Play是个实现Controller的接口
	 private File              file,listFile;//利用File类结合JFileChooser进行文件打开操作,后则与list.ini有关
	 private Container         c;
	
	 private String            title,listIniAddress;//标题
	 private FileDialog        fd;
	 private JPanel            panel,panelSouth;
	 private Icon              icon; 
	 private JLabel            label,listB;//用来显示图标
 
   

    
    
 
 
 MediaPlayer()//构造函数
 {
      super("java媒体播放器");//窗口标题
     
      c=getContentPane();
      c.setLayout(new BorderLayout());
                                //c.setBackground(new Color(40,40,95));
     
      fileName=new Vector(1);
      dirName=new Vector(1);
      numList=new Vector(1);        //构造三个容器用于支持播放清单





      listFile=new File("list.ini");//直接存于此目录
      Thread readToList=new Thread(this);

  
	  list=new JList();
	  list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
	  list.setSelectionForeground(new Color(0,150,150));
	  list.setVisibleRowCount(10);
	  list.setFixedCellHeight(12);
	  list.setFixedCellWidth(250);
	  list.setFont(new Font("Serif",Font.PLAIN,14));
	  list.setBackground(new Color(40,40,95));
	  list.setForeground(new Color(0,128,255));
	  //list.setOpaque(false);
	  list.setToolTipText("右键有更多惊喜哦");//创建播放清单并设置各个属性
	  list.addMouseListener(new MouseAdapter()
	  {
	   public void mouseClicked(MouseEvent e)
	   {
	                if (e.getClickCount() == 2) //判断是否双击
	                {
	                   index = list.locationToIndex(e.getPoint());//将鼠标坐标转化成list中的选项指针
	                   createPlayer2();
	                   System.out.println("Double clicked on Item " + (index+1));
	                }
	            }
	        
	        
	        
	            public void mouseReleased(MouseEvent e)
	            {
	             checkMenu(e);
	            }
	
	  }
	  );

	  scroll=new JScrollPane(list);//用于存放播放列表
	
	  
	  readToList.start();//启动先程,加载播放列表
	  
	  try
	  {
	  	
	  	Thread.sleep(100);
	  
	  }
	  catch(InterruptedException e)
	  {
	  	
	  	e.printStackTrace();
	  	
	  }
	  
  
  
  




 /* try
  {
   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  }
  catch(Exception e)
  {
   e.printStackTrace();
  }
  */ 
  
  
  
  
	  bar=new JMenuBar();
	  setJMenuBar(bar);//此两行创建菜单栏并放到此窗口程序
	  bar.setBackground(new Color(10,160,173));
	  
	  fileMenu=new JMenu("文件");
	  bar.add(fileMenu);
	  
	  choiceMenu=new JMenu("控制");
	  bar.add(choiceMenu);
	  
	  voiceMenu=new JMenu("声音");
	  bar.add(voiceMenu);
	  
	  
	  helpMenu=new JMenu("帮助");
	  bar.add(helpMenu);
	 
	  
  
  
	  openItem    =new JMenuItem("打开文件");
	  openDirItem =new JMenuItem("打开目录");
	  closeItem   =new JMenuItem("退出");
	  openItem.addActionListener(this);
	  openDirItem.addActionListener(this);
	  closeItem.addActionListener(this);
	  fileMenu.add(openItem);
	  fileMenu.add(openDirItem);
	  fileMenu.add(closeItem);
	  
	  onTop=new JCheckBoxMenuItem("播放时位于最前面",top);   //设置ontop菜单项
	  choiceMenu.add(onTop);
	  
	  onTop.addItemListener(new ItemListener()    //增加监听事件
	  {
	  	
	    public void itemStateChanged(ItemEvent e)
	   {
	       if(onTop.isSelected())
	           top=true;
	       else 
	           top=false;
	       setAlwaysOnTop(top);
	   }
	  }
	  );
  
  
  
	  choiceMenu.addSeparator();//加分割符号
	  
	  buttonGroup=new ButtonGroup();
	  buttonValues=new JRadioButtonMenuItem[3];
	  for(int bt=0;bt<3;bt++)
	  {
	   buttonValues[bt]=new JRadioButtonMenuItem(content[bt]);
	   buttonGroup.add(buttonValues[bt]);
	   choiceMenu.add(buttonValues[bt]);
	  }
	  buttonValues[0].setSelected(true);
	  choiceMenu.addSeparator();
	  

  
  
  
  
	  voicehigh=new JMenuItem("升高");
	  voiceMenu.add(voicehigh);
	  voicehigh.addActionListener(this);
	     
	  voicelow=new JMenuItem("降低");
	  voicelow.addActionListener(this);
	  voiceMenu.add(voicelow);     //菜单栏设置完毕
  
  
      about=new JMenuItem("关于播放器");
      helpMenu.add(about);
      about.addActionListener(this);
      
      info=new JMenuItem("播放器使用指南");
      helpMenu.add(info);
      info.addActionListener(this);
      
      
	  panel=new JPanel();
	  panel.setLayout(new BorderLayout());
	  c.add(panel,BorderLayout.CENTER);
	  
	  panelSouth=new JPanel();
	  panelSouth.setLayout(new BorderLayout());
	  c.add(panelSouth,BorderLayout.SOUTH);
	  
	  icon=new  ImageIcon("紫花.jpg");//
	  label=new JLabel(icon);
	  panel.add(label);
	  
	  popupMenu=new JPopupMenu();
	  del      =new JMenuItem("删除");//鼠标右键弹出菜单对象实例化
	  popupMenu.add(del);
	  del.addActionListener(this);
	  
	  delAll   =new JMenuItem("全部删除");
	  popupMenu.add(delAll);
	  delAll.addActionListener(this);
	  
	  reName   =new JMenuItem("重命名");
	  popupMenu.add(reName);
	  reName.addActionListener(this);
	  
	 
  
	  scroll=new JScrollPane(list);//用于存放播放列表
	  listB=new JLabel(new ImageIcon("雪景2.jpg"),SwingConstants.CENTER);
	  
	  panelSouth.add(listB,BorderLayout.NORTH);
	  panelSouth.add(scroll,BorderLayout.CENTER);
	  
	  
	  dialog1=new DialogDemo(this,"说明");
	  
	  this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);//设定窗口关闭方式
	
	  this.setLocation(400,250);//设定窗口出现的位置
	  //this.setSize(350,320);//窗口大小
	  setSize(450,430);
	  this.setResizable(false);//设置播放器不能随便调大小
	  this.setVisible(true);//设置窗口显示
  
  
        TypeWord type=new TypeWord();//动画显示模块
		type.isStandalone=true;
		JFrame frame;

        frame=new JFrame()  //the constructor of frame
        {
			protected void processWindowEvent(WindowEvent e)
			{
				super.processWindowEvent(e);
				if(e.getID()==WindowEvent.WINDOW_CLOSING)
				{
					//System.exit(0);
                   // type.stop();
                  //  frame.setVisible(false);  //this three lines do not work
				}
			}
		
			public synchronized void setTitle(String title)
			{
				super.setTitle(title);
				enableEvents(AWTEvent.WINDOW_EVENT_MASK);
			}
		};
		
		frame.add(type,BorderLayout.CENTER);
		type.init();   //线程开始即动画初始化
		type.start();  //线程开始动画显示
		Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
		frame.setLocation((d.width-frame.getSize().width)/2-112,(d.height-frame.getSize().height)/2-90);
		frame.setVisible(true);
		frame.setBackground(Color.GREEN);
		frame.setSize(450,100);
        //c.add(frame,BorderLayout.NORTH);这句加不进去,不知怎么把动画加到播放器中
       //add(frame,BorderLayout.NORTH);
	   //  desktop.add(frame);
  
  
 }
 
 public void actionPerformed(ActionEvent e)
 {
	  if(e.getSource()==openItem)//getSource()判断发生时间的组键
	  {
	
	      openFile();


	  }
	  if(e.getSource()==openDirItem)//打开目录
	  {
	      openDir();
	  }
	  if(e.getSource()==closeItem)//退出播放器
	  {
	       exity_n();
	   //System.exit(0);
	  }
	  if(e.getSource()==about)
	  {
	   
         JOptionPane.showMessageDialog(this,"This is a simple mediaplayer! Thanks!","content",
         JOptionPane.INFORMATION_MESSAGE);	   
         //System.out.println("shengying:"+getVolumeLevel());
	   
	  }
	  if(e.getSource()==del)
	  {
	

			fileName.removeElementAt(indexForDel);
	  	    dirName.removeElementAt(indexForDel);
	        numList.removeAllElements();//从三个容器里面移除此项
	        Enumeration enumFile=fileName.elements();
	        
	        while(enumFile.hasMoreElements())
	       {
	             
	           numList.addElement((numList.size()+1)+"."+enumFile.nextElement());
	    
	                                   //numList添加元素,显示播放里表中
	       }
	   
	       list.setListData(numList);
	   	   if(index<indexForDel)
	   	         list.setSelectedValue(numList.elementAt(index),true);
	       else
	       {
	           if(index==indexForDel);
	           else
	           if(index!=0)
	            list.setSelectedValue(numList.elementAt(index-1),true);
	       }
	   
	  }
	  
	  if(e.getSource()==delAll)//全部删除
	  {
	  	
	    fileName.removeAllElements();
	    dirName.removeAllElements();
	    numList.removeAllElements();
	    list.setListData(numList);
	  }
	  
	  if(e.getSource()==reName)//重命名
	  {
	    
	    String name;
	    try
	    {
	       name=reNames();
	       fileName.setElementAt(name,indexForDel);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -