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

📄 java播放器.java

📁 Java 图形界面入门实例
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -