java播放器.java

来自「Java 图形界面入门实例」· Java 代码 · 共 56 行

JAVA
56
字号
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Java播放器
{  private Frame frame;
   private Button play,loop,shop,view;
   private TextField textBox;
   private FileDialog openFile; 

   public void playTool()
   { frame=new Frame("Java播放器");
     view=new Button("浏览");
     play=new Button("播放");
	 loop=new Button("重放");
	 shop=new Button("停止");
	 textBox=new TextField(20);
	 frame.setLayout(new FlowLayout(FlowLayout.CENTER));
	 openFile=new FileDialog(frame,"打开文件",FileDialog.LOAD);
	 frame.add(view);
	 frame.add(play);
	 frame.add(shop);
	 frame.add(loop);
	 frame.setSize(30,30);
	 frame.setVisible(true);
   }


   public void actionPerformed(ActionEvent evt)
   {  String str=evt.getActionCommand();
	  if(str=="浏览")
	  {	openFile.show();
        String fileName=openFile.getDirectory()+openFile.getFile();
		textBox.setText(fileName);
		AudioClip music=AudioClip.newAudioClip("F:\\java\\java\\passport.mid");
		
	   }
	   else if(str=="播放")
       {  music.play(); }
	   else if(str=="停止")
	   {   music.shop(); }
	   else if(str=="重放");
	   {  music.loop();  }
   }

   class WindowClosing extends WindowAdapter
   {  public void windowClosing(WindowEvent ev)
	   { System.exit(0);}
   }

   public static void main(String args[])
   {  Java播放器 test=new Java播放器();
      test.playTool();
    }
}

⌨️ 快捷键说明

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