激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - 一個簡單的Java音樂播放器

一個簡單的Java音樂播放器

2020-11-09 15:29PettyKoKo Java教程

這篇文章主要為大家分享一個簡單的Java音樂播放器,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Java音樂播放器展示的具體代碼,供大家參考,具體內容如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package KKMusic;
 
 import java.applet.Applet;
 import java.applet.AudioClip;
 import java.awt.BorderLayout;
 import java.awt.EventQueue;
 
 
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.border.EmptyBorder;
 import java.awt.CardLayout;
 import javax.swing.JButton;
 import javax.swing.JFileChooser;
 import javax.sound.sampled.FloatControl;
 import javax.sound.sampled.SourceDataLine;
 import javax.swing.GroupLayout;
 import javax.swing.GroupLayout.Alignment;
 import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
 import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import java.awt.event.ItemListener;
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.awt.event.ItemEvent;
 import javax.swing.JMenu;
 import javax.swing.JTextField;
 import javax.swing.SwingConstants;
 import javax.swing.JSlider;
 import java.awt.event.MouseMotionAdapter;
 import java.awt.event.MouseEvent;
 
 
public class Mp3 extends JFrame {
 
private JPanel contentPane;
 File file;//聲明文件對象
 String filename;
 JFileChooser chooser=new JFileChooser();//創建一個文件選擇器
 private JTextField xiaoxi;
 boolean loop=false;
 AudioClip adc;//聲音音頻剪輯對象
 SourceDataLine line;
 private FloatControl volume = null;
 /**
 * Launch the application.
 */
 public static void main(String[] args) {
 EventQueue.invokeLater(new Runnable() {
 public void run() {
 try {
 Mp3 frame = new Mp3();
 frame.setVisible(true);
 } catch (Exception e) {
 e.printStackTrace();
 }
 }
 });
 }
 
 
/**
 * Create the frame.
 */
 public Mp3() {
 setTitle("\u97F3\u4E50\u64AD\u653E\u5668");
 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 setBounds(100, 100, 265, 333);
 
JMenuBar menuBar = new JMenuBar();
 setJMenuBar(menuBar);
 
JMenu mnNewMenu = new JMenu("\u6587\u4EF6");
 menuBar.add(mnNewMenu);
 xiaoxi = new JTextField();
 xiaoxi.setColumns(10);
 xiaoxi.setText("歡迎使用本播放器");
 JMenuItem dakai = new JMenuItem("\u6253\u5F00");
 dakai.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 int value=chooser.showOpenDialog(chooser);//接受文件選擇器的狀態
 if(value==chooser.APPROVE_OPTION){
 file=chooser.getSelectedFile();//返回選中文件
 filename=file.getName();
 String flag=filename;
 xiaoxi.setText(flag);
 try {
 if(adc!=null)
 adc.stop();
 URL url=new URL("file:"+file.getPath());//創建資源定位
 adc=Applet.newAudioClip(url);
 //adc.play();
 
} catch (MalformedURLException e1) {
 // TODO Auto-generated catch block
 e1.printStackTrace();
 System.out.println("不能播放!");
 }
 }
 }
 });
 mnNewMenu.add(dakai);
 
JMenuItem tuichu = new JMenuItem("\u9000\u51FA");
 tuichu.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 
 dispose();
 if(adc!=null)
 adc.stop();
 return ;
 }
 });
 
mnNewMenu.add(tuichu);
 contentPane = new JPanel();
 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
 setContentPane(contentPane);
 
JButton playbtn = new JButton("\u64AD\u653E");
 playbtn.setHorizontalAlignment(SwingConstants.LEFT);
 playbtn.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 
 String flag="正在播放:"+filename;
 if(adc==null){
 flag="請選擇播放的音樂";
 xiaoxi.setText(flag);
 return;
 }
 adc.play();
 xiaoxi.setText(flag);
 }
 });
 
JButton stopbtn = new JButton("\u6682\u505C");
 stopbtn.setHorizontalAlignment(SwingConstants.LEFT);
 stopbtn.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 adc.stop();
 String flag="停止播放音樂:"+filename;
 xiaoxi.setText(flag);
 }
 });
 
JButton againbtn = new JButton("\u5FAA\u73AF");
 againbtn.setHorizontalAlignment(SwingConstants.LEFT);
 againbtn.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 loop =!loop;
 String flag="";
 ; if(loop){
 adc.play();
 adc.loop();//循環播放
 flag="循環播放:"+filename;
 }
  else{
  adc.play();
  flag="順序播放"+filename;
  }
  xiaoxi.setText(flag);
 }
 });
 
 
 
 
GroupLayout gl_contentPane = new GroupLayout(contentPane);
 gl_contentPane.setHorizontalGroup(
 gl_contentPane.createParallelGroup(Alignment.LEADING)
 .addGroup(gl_contentPane.createSequentialGroup()
 .addContainerGap()
 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
 .addComponent(xiaoxi, Alignment.LEADING)
 .addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
 .addComponent(playbtn, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(ComponentPlacement.UNRELATED)
 .addComponent(stopbtn, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(ComponentPlacement.UNRELATED)
 .addComponent(againbtn, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)))
 .addContainerGap(15, Short.MAX_VALUE))
 );
 gl_contentPane.setVerticalGroup(
 gl_contentPane.createParallelGroup(Alignment.TRAILING)
 .addGroup(gl_contentPane.createSequentialGroup()
 .addComponent(xiaoxi, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
 .addPreferredGap(ComponentPlacement.UNRELATED)
 .addPreferredGap(ComponentPlacement.RELATED, 173, Short.MAX_VALUE)
 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
 .addComponent(playbtn)
 .addComponent(stopbtn)
 .addComponent(againbtn))
 .addContainerGap())
 );
 contentPane.setLayout(gl_contentPane);
 }
 
}

運行結果如下:

一個簡單的Java音樂播放器

一個簡單的Java音樂播放器

一個簡單的Java音樂播放器

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲视频综合网 | 999久久久久久 | 成人视屏在线 | 欧美精品一区二区久久久 | 91免费视频版 | 久久亚洲春色中文字幕久久 | 欧美zoofilia杂交videos | 国产激爽大片在线播放 | 精品国产一区二区三区久久久 | 日韩视频一区二区三区四区 | 久草在线观看首页 | 欧美一级高清片在线 | 99精品在线观看 | 91嫩草丨国产丨精品入口 | 久色免费 | 欧美日本中文字幕 | 一级α片免费看 | 国产乱淫a∨片免费观看 | 久久免费视频7 | 黄色小视频在线免费看 | 免费一级肉体全黄毛片 | 中文字幕欧美亚洲 | 久久av喷吹av高潮av懂色 | 久久中文字幕在线观看 | 亚洲性夜色噜噜噜7777 | 欧美14一15sex性hd | 久久久久久久黄色片 | 91羞羞 | 国产精品九九久久一区hh | 中国美女一级黄色片 | 国产成人综合在线观看 | 日韩欧美动作影片 | 精品亚洲午夜久久久久91 | 老女人碰碰在线碰碰视频 | 欧美性受xxxx白人性爽 | 伊人av影院 | 欧美成人激情在线 | 55夜色66夜色国产精品视频 | 欧美一区二区三区成人 | 欧美一级做一级爱a做片性 久久久资源网 | 精品国产欧美一区二区 |