该用户从未签到
|
用java实现简单的mp3播放功能,麻雀虽小,五脏俱全。7 I/ R* h" p8 a
- package com.jifeng.view;
& z. g9 K# o8 n7 V
# I+ M7 @ @8 g& w5 q, m- import java.awt.Checkbox;4 o1 {( Q$ |, p0 G
- import java.awt.Color;
3 g$ T! v( M1 r! K6 p' J# x - import java.awt.Dimension;- U/ S9 f$ o" i/ I
- import java.awt.MenuItem;" \: x4 h m2 ]# F2 L' @" ?) [
- import java.awt.Rectangle;: q" p; t( A) |
- import java.awt.event.ActionEvent;
7 X. o. U) I; V, u o2 C - import java.awt.event.ActionListener;0 r6 v$ l U, O. v5 m) E4 f/ i
- import java.awt.event.ItemEvent;
% Y M5 _5 Z: A. U" c - import java.awt.event.ItemListener;9 B5 R) F9 g' n
- import java.awt.event.MouseAdapter;6 _$ V& I7 s b+ I3 }
- import java.awt.event.MouseEvent;
8 c% t+ d3 c7 P3 {0 ~+ A1 M5 z - import java.awt.event.MouseListener;
: B2 U Z! X S* S8 T - import java.io.File;6 E& H) U( I! G8 @* i8 ~/ H! V0 x
- import java.util.List;. ?1 S* i8 P, O) J
- 7 R) W1 `" r4 ]' z9 N
- import javax.swing.DefaultListModel;
9 v' O& ^; }# j q2 m - import javax.swing.ImageIcon;8 ~" d: e/ A+ L0 R
- import javax.swing.JButton;
7 X, ` e, T+ t - import javax.swing.JCheckBox;
( t5 W( N# A7 T3 B0 j; o - import javax.swing.JFileChooser;
1 \6 G3 D- Y( p - import javax.swing.JFrame;0 z# b& s3 J3 r/ Z
- import javax.swing.JLabel;. j! [; i1 C: U; |! z- Z2 e
- import javax.swing.JList;
8 o9 s% l( x |2 m5 F/ o2 ^, \ - import javax.swing.JMenu;
6 s+ [, U5 H4 y# Y - import javax.swing.JMenuBar;2 K& m/ O9 S; ]% a" L8 J1 s
- import javax.swing.JMenuItem;/ t% g+ n' F( ~
- import javax.swing.JOptionPane;, I' U% G+ x% v% }+ q8 b. O7 q' B
- import javax.swing.JPanel;% l1 ~3 c- n x4 h+ Q! V
- import javax.swing.JSlider;5 Q5 z) ^7 j. K5 m+ e3 d% j
- import javax.swing.SwingConstants;
! M T& R! _4 U - import javax.swing.Timer;
: L8 E i4 W: ?9 U3 F, s - import javax.swing.UIManager;* a- ~$ z6 \4 i+ }3 W
- import javax.swing.UnsupportedLookAndFeelException;
z. p7 f0 j2 u; w a; J K - import javax.swing.event.ChangeEvent;5 S, q# M3 t: B5 S( {0 |
- import javax.swing.event.ChangeListener;- I4 w5 |# x# v
- 2 }3 D. s0 _. e! F+ l" C& h
- import mp3x.ctl.Mp3TVShow;( q6 P# a/ [) n* V& o! _8 i) {
/ l) g, }" w" h* Z5 _: ]' v- import org.jvnet.substance.skin.SubstanceGreenMagicLookAndFeel;5 _. L; `, { D. `9 e
- l( L! E; q9 o1 k# d* P
- import com.jifeng.model.Mp3Info;
3 f' F6 @! K( G3 B+ x% p - import com.jifeng.util.MainControl;2 M2 Z0 o8 a5 c9 C$ M0 x8 v/ v4 R& P
- . A l% I6 \# Z( V3 \) d. {6 A
- public class Mp3View extends JFrame{& e: S/ K' I5 k9 N
- " l- P' z. v2 }, {' G$ [0 E* y' R
- private JSlider processSlider = null;" X8 R; C6 s0 V2 n. t
- private JSlider volumnSlider = null;
% H3 e' s1 \/ i. b% g9 N - private JButton playButton = null;% W( i; E8 S b, m3 z
- private JButton stopButton = null;
1 \; p/ A4 U9 p+ e - private JButton upButton = null;& ~9 r" Z; p" y6 ]( E! t
- private JButton downButton = null;
4 m. {3 C, U( K0 ]9 {1 B - private JButton addButton = null;4 w( q3 `2 V7 T7 G: [
- private JButton deleteButton = null;+ N' a8 T" j6 E' h4 J! `
- private JButton faseButton = null;% D1 P- v8 _3 `. Q; _ X, f( ^
- private JButton slowButton = null;
1 B/ v3 I3 x. ~6 i, |: E9 Z5 m/ e - private JButton SfaseButton = null;7 w+ w* W4 x7 |
- private JButton SslowButton = null;6 e6 A1 Q9 G: ?/ C2 g
- private JList list = null;
, U; C. i6 r; u* O9 V5 O1 t - private JLabel l_name = null;! I3 q* Z1 x6 }0 ]
- private JPanel back;
' _: `" q/ L0 V# h6 j) @) P - private JLabel [] l_texts = new JLabel[9];6 |: ^2 b6 j; Q5 \. k; h2 G% d6 M
- private JLabel [] l_text = new JLabel[3];
6 ]3 F0 L8 l# ~, ^8 ^3 x& A* h r - private JLabel l_time = null;/ H3 G' s4 C; i
- private Checkbox checkBox = null;; n1 M% y6 F9 B) k/ w, |
- private JCheckBox treanBox = null;4 s e% t' j: {' m
- private JCheckBox muteCheckBox = null;
+ d+ I. k. K/ W( T3 ]1 ] - private JMenuBar mb;7 Z5 D6 J1 t! Y* z! `
- private JMenu menu;
3 E' |0 Q+ B! S2 ~0 j5 z0 ` -
6 {/ h& X1 q1 M - private boolean progressSliderDrag = false;
$ n7 T. ^+ {; A S) ^8 l6 H - private DefaultListModel model;
2 ~0 Q$ V1 n/ ~* L: A2 N - private MainControl control = null;
& o" w( n( _) ~( M - private List<Mp3Info> lists;
4 F- \* ]! ^0 y8 N - private Mp3Info currentMp3;
! W2 c" X5 m. d! Y {( W; ^8 I - private static int crrentList = 0;1 ]! y. @" F) e4 \3 D
- private Mp3TVShow mp3TVShow = new Mp3TVShow();
; F7 s' b5 R2 k. r, L g - private Mp3TVShow mp3TVShow1 = new Mp3TVShow();
8 o( l H d' m0 [0 s - private List<Long> times = null;) a5 I' u' }. ~+ k* d" B4 A# V$ u. C" S
- private List<String> messages = null;3 d: [0 ^; ]4 f2 G
-
) h: L( K! Y$ G8 g* R# a/ @ - private Timer progressTime = null;
+ ], k4 U+ D9 r* p - private Timer nameTime = null; V: }3 j5 N) d% e% O) [4 U' h9 n
- private Timer textTime = null;
3 ^1 U7 a' G7 m& K4 U" L - private static int currentValue = 0;
+ C" Z j" e: n+ U! v; i - private static long currentTime = 0;6 q5 \1 H* z$ M
- private static int L_WIDTH = 40;
. s6 m0 l9 @! R. M. d - private static int currentLocation = 4;# G' x& y5 X! q, Z% z Q
- private static int currentLoca = 1;
" T( I$ s8 H" ?1 a -
" [# W1 \1 C* @2 ]+ q4 g9 ~. j - private boolean tranType = false;
9 d! K/ R3 l, F+ n* Z - , o) l: |5 Y: B$ K) X
- public enum Mp3Status{4 I- |# n! H7 h3 p
- PLAY,PAUSE,STOP
( d1 v8 @8 c; E+ y3 J - }- _. L+ E: O( [
- private Mp3Status currentStatus = Mp3Status.STOP;
3 c( g( O, W5 D( p7 ]5 C, y; { -
1 V4 B" c- M! G' ^( P - public Mp3View(){
9 u% F: k! f; W( A/ { - setSize(760,630);3 L; g. k2 w, G8 |. {
- //设置位置
3 }* A! d, m1 L, s0 x% E - setLocation(200, 50);
2 k3 h" h/ ]% u - setLayout(null);5 r5 U" P9 `3 y" W
- initCompent();
1 c. d* v8 H L+ v - initMenu();
( w c- d+ N+ P; |. e% f2 |5 E - this.setJMenuBar(mb);
. B, [8 I5 p K: J4 ^5 U2 f& B8 _/ J - //设置可见
; `6 E$ \* ~- O- V ?6 V - setVisible(true);
9 ]* o3 v% O, }9 p ~: [! M - //点关闭按钮时退出
7 J3 V! u, S# p5 w - this.setResizable(false);% A2 Y& z3 P- S/ a& l2 J
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
$ M+ {9 Y: s/ @) Z/ i! ? -
) I3 Q1 S* `$ \8 r9 ?1 J - }
4 S, T$ X% ?& I" n - private void initMenu(){
) q% q1 p* N# Y7 L - mb = new JMenuBar();
: D* Z5 d4 R6 q; T) j* A& a/ ^ - menu = new JMenu("帮助");& N. \( W/ g6 `$ m
- mb.add(menu);
8 F$ o: K& E5 e" h3 F" @- z8 | - JMenuItem item1 = new JMenuItem("帮助");, }2 \4 Y1 f, ^! v, G' ?
- item1.addActionListener(new ActionListener(){- ~* p8 m7 b6 ^
- 7 C# l* d. z( n
- @Override& I e- s6 @9 o, Q# D4 [ J0 q
- public void actionPerformed(ActionEvent e) {* s4 F2 H5 L3 e4 O( b3 F
- System.out.println("hello ");
& O; \, q7 f7 f: t9 z9 W* X, O4 k - JOptionPane.showMessageDialog(null, "MP3使用说明:\n 该MP3实现了播放器的基本功能,除了界面上的功能 \n 在歌词上方的" +* n2 m1 E. J. \
- "< << > >> 是用来处理歌词同步的,<<表示歌词时间-0.5秒\n <表示歌词时间-0.1秒>表示歌词时间+0.1秒>>表示歌词时间+0.5秒"); w8 s, F; {* X4 j
- }
/ T3 _# k9 n1 G3 K8 | |- d- |8 P: r - 1 P0 r/ |, v' f1 m1 n
- });
- B2 ?4 X" l' D/ B. V - menu.add(item1);. K/ w$ }7 ?8 m& a; i" V4 \
- }/ g1 X2 v; c- H/ F
- private void initCompent(){( I. [, Q# B$ K2 _
- processSlider = getProcessSlider();: s' V& }! q& B, a
- this.add(processSlider);/ z& z/ F4 D! v# X+ L' H
- playButton = getPlayButton();
6 X) A( N- C9 G, d! D5 d& c - this.add(playButton);* ~& E$ g. s' U: z
- stopButton = getStopButton();! l! h- o+ w$ Z. e# P2 P( [# u
- this.add(stopButton);
6 I6 H: F& @, f7 F+ _4 z, S$ t - upButton = getUpButton();
6 L0 z- `5 d$ O6 T - this.add(upButton);
. L- ?0 c8 h( E; G5 _; A! s - downButton = getDownButton();
: z5 e1 D9 J$ m - this.add(downButton);% }8 M( J8 Q$ x" M3 g( t
- addButton = getAddButton();( L: S g( {$ B* ?/ ?
- this.add(addButton);
3 r& u4 B. @, Z& y - deleteButton = getDeleteButton();
; P! x+ K2 {1 ], F9 m( A - this.add(deleteButton);8 g$ W0 U& R# Y0 ?0 x1 [4 A+ J
- list = getList();
: x/ ~1 z- }* h* V6 D - this.add(list);' V, A" T# Z0 `: y
- //隐藏脉冲
$ {9 V+ C4 M* k4 F2 R - checkBox = getCheck();! @5 n6 R+ f, H+ P+ \. B3 r6 l
- this.add(checkBox);, Q; O) ~! c' {3 ]# c9 K
- //设置音量3 }' a* b/ o: n' ]: z: A
- volumnSlider = getVolumnSlider();, V' @1 t) z9 z" q
- this.add(volumnSlider);
1 F2 M& n# U1 t - muteCheckBox = getMuteCheckBox();9 i* _( T0 g# G: q
- this.add(muteCheckBox);
; @- e+ A) ^. d' U, I - //设置循环模式' u9 t& {9 h O
- treanBox = getTranBox();6 |6 k, {2 b/ a, h* N! o5 @& d
- this.add(treanBox);
& D, m6 w. A( S, | k - //显示时间# |2 l) X0 z. @) E
- l_time = new JLabel();
% A0 T. g0 c& _) G' o - l_time.setBounds(293, 40, 40, 20);
0 d1 d1 T! p3 R! Q - l_time.setForeground(Color.white);- Y+ J5 F N& s6 P( X9 j s1 e
- l_time.setText("00:00");: V+ \1 j7 ]( ^- k8 q! _
- this.add(l_time);; [# |8 p. N; F: ~7 h" }) l) o
- //调整歌词: z2 C2 X8 O) f; I
- JLabel labels = new JLabel();- a% } S. }" z7 _
- labels.setText("调整歌词进度:");* ?; D$ p( T& O. v6 u7 @2 b( a
- labels.setFont(new java.awt.Font("Dialog",0,15));
* b2 ^# k {! G+ G - labels.setForeground(Color.yellow);: A; C7 E6 j" x- h
- labels.setBounds(375, 70, 100, 20);
0 g Q0 Q2 b# _- s6 |& w - this.add(labels);
# I6 U$ T/ k2 _. l+ X - faseButton = getFastButton();" l0 r: ]7 J& A8 H
- this.add(faseButton);* e+ l! ], _) L& B% |+ P
- slowButton = getSlowButton();
z: ]; I. f; r- ] G) P7 M - this.add(slowButton);
; r+ }/ X! C# K - SfaseButton = getSFastButton();, H! N$ a L: l5 R1 @+ I" E
- this.add(SfaseButton);9 {2 _: X/ z3 F. G$ M" |
- SslowButton = getSSlowButton();" E& A! I1 {# ?4 k0 n, [
- this.add(SslowButton);
2 j# F5 ^# W8 A7 v- I: @8 U& H8 Z - //设置脉冲
/ ?& b7 {. I5 J - mp3TVShow.setBounds(360, 100, 350, 270);
- q" u* W" l8 Z7 i$ j* `( q - //mp3TVShow.setVisible(false);
7 @$ o* A) w3 G# [' ~ - this.add(mp3TVShow);
4 X6 t% j& q7 E - mp3TVShow1.setBounds(350, 80, 1, 1);
- X% a& }* O+ D - //mp3TVShow.setVisible(false);
/ u1 j( u9 c) I7 K - this.add(mp3TVShow1);
; H1 k K2 }) b1 w% L& x; F - l_name = getNameLabel();, a( Z$ ^. P4 @* p( g6 p
- this.add(l_name);
! E7 q- W C8 [8 t' N - //歌词3 G6 J+ Z; z: J# o, W
- for(int i = 0; i<3; i++){0 f1 B) E% O* c: p
- l_text[i] = new JLabel();
5 J! y5 r2 m' F5 d: m - l_text[i].setHorizontalAlignment(SwingConstants.CENTER);
# A& X+ m! ]. B4 F. V& Y/ l4 ? - //l_text[i].setText("hello world");. F+ d7 p+ S( W- N6 r
- l_text[i].setBounds(360,400+ i * L_WIDTH,330,20);" _ j6 D1 @; Y$ k$ h
- this.add(l_text[i]);
/ U- b# a) o3 b: |( f* Q - }
/ H) i3 ~2 Y- b! e. w7 \ -
8 \4 z* D) `& M# ^4 m% F# e - " l6 W: f6 w6 s# I+ @
- control = new MainControl();
2 N' _6 y6 T c - nameTime = new Timer(100,new TextListener(l_name));' ~" V) W Q, D, Q
- nameTime.start();' W- ^/ ^) h' |/ i/ g" m2 V, Q. N9 R& n
- progressTime = new Timer(1000,new MyListener(processSlider));
& f, e5 [+ U7 ^5 L3 Y+ @ - textTime = new Timer(10,new LrcListener());) z# C8 B/ g8 q7 P0 t& m
- }0 U C [& s2 k4 |, {2 c# x
- $ l5 _2 { d( c% v" J
- private JButton getFastButton() {
+ l9 F- @, Z, j$ E+ b - if (faseButton == null) {
. ^* Z$ C" l' u* I9 w - faseButton = new JButton();2 b! r. {6 w7 G# P
- faseButton.setBounds(530, 70,25, 20);, n. z: D" r8 m, Z4 e
- faseButton.setText(">");+ Y) @. k. V! W. |& U9 D
- faseButton.addActionListener(new ActionListener(){' n! `* I$ c5 h8 D- I
-
! |0 ]6 G2 b: h2 X3 b& [ - public void actionPerformed(ActionEvent e) {
; ^" D* r+ L, h - currentTime = currentTime + 200;/ ^6 W* w: m- b
- }
- B; Z1 ?( ^; |$ G0 W+ R) y7 o - 5 _% O8 e1 v, _& _ g. k/ R7 v: q) n
- });
3 @% O% Q1 P' f# ]) V, [+ ?% q, v( x* ` - }7 y' Y- [% c- T6 E: n
- return faseButton;0 ^" ]/ A5 ^9 c0 T3 y; j6 V
- }' I( ^4 s/ x6 Q$ K
- private JButton getSlowButton() {: i1 B6 r, n, y" m' z2 w+ k
- if (slowButton == null) {
( M$ y0 X* X- ^$ D) _ - slowButton = new JButton();3 U# D1 T/ w+ W h8 E0 S8 a
- slowButton.setBounds(500, 70,25, 20);' i, x w- b) z* J7 b9 i& Y
- slowButton.setText("<");2 d" m' Z: D# H/ ~7 A: w9 l$ h
- slowButton.addActionListener(new ActionListener(){# k) A% d! k; ?2 A0 ?
-
. t A# ~! M/ H; U - public void actionPerformed(ActionEvent e) {
) l: s9 m# Y! a6 m6 r - currentTime = currentTime - 200;: n2 q5 w8 u, C5 E4 B
- }
+ J* A0 a% o6 ?4 j. J - ; v+ b$ \( B( T" H6 f
- });
# {7 d3 y% A3 x7 Q! g) X$ q! U - }
3 s7 h. f9 w8 q( G) J - return slowButton;
( P e1 ^9 I5 a/ h+ n - }" |0 `1 R8 G) @, M* O1 H
- private JButton getSFastButton() {( Y( Q0 v, |0 c8 s" d2 b; D, `, l8 g' S
- if (SfaseButton == null) {
* K. h7 a& J$ ~) l" ~, B - SfaseButton = new JButton();& K3 {) K L9 i+ r( l3 a+ l
- SfaseButton.setBounds(560, 70,25, 20);
; r& `1 t F5 W; A - SfaseButton.setText(">>");
' q/ b2 u8 \4 H) I" L* }/ X - SfaseButton.addActionListener(new ActionListener(){1 L3 H- G0 r. {* O2 Y9 B, f
-
% I$ s. Q$ I) [2 X" [: t& e7 R - public void actionPerformed(ActionEvent e) {
% U7 l5 `# x' n5 C+ c: ~0 P% K - currentTime = currentTime + 500;) q( ?( p! F, A
- }1 I- l0 A) P0 i! X1 F0 y
- ) b/ d# D5 a3 R/ Z6 v/ f1 ~9 _
- });- q3 ^5 _/ G8 Q9 |4 g% W6 _8 _
- }
+ m N8 |6 K8 { - return SfaseButton;
/ M0 `5 m9 g3 ? - }* y: R3 m% q# R1 x6 U
- private JButton getSSlowButton() {" j3 w6 j5 Y3 w& c0 }
- if (SslowButton == null) {/ y3 J9 {' ~& H
- SslowButton = new JButton();% e7 ?* B- h/ x% W* t; \
- SslowButton.setBounds(470, 70,25, 20);
( s/ n. j' R8 C8 q, F, ` - SslowButton.setText("<<");
: p7 _ |- z) y- J" t - SslowButton.addActionListener(new ActionListener(){' D7 p* ^/ u# F" z1 Z" Y
- $ R& k4 ?7 J( R4 X
- public void actionPerformed(ActionEvent e) {
0 j' k6 a3 c3 e z# L; [5 ? - currentTime = currentTime - 500;. L" u6 D' d8 N; I, ?* _+ Y
- }' b2 e/ o7 w1 w) c8 p
8 {0 q, Y/ Y, y# U& w9 f4 x- });7 q+ c. o3 E* X* ^5 A
- }
4 ^" ]0 Y! N: r, i. l - return SslowButton;
7 @& m6 ?3 I1 g6 w L - }
# O6 c: Y; o2 ` - private Checkbox getCheck(){
. |# w# A' I W - if(checkBox==null){: U- y, W ]2 U) r7 c4 b# T
- checkBox = new Checkbox();. F# ^0 {9 o1 j: \( |
- checkBox.setLabel("隐藏脉冲");) _& y) ]6 F8 E! l' k n
- checkBox.setBounds(600, 70, 200, 20);
$ Y& i1 U5 p7 i - checkBox.addItemListener(new ItemListener(){0 Y6 `- O* [2 ]& N
- . o( S% k5 L: L: `& u
- public void itemStateChanged(ItemEvent e) {
& ]: e# g* z* d+ N - if(checkBox.getState()){: n9 r$ s1 H8 Y2 a6 b( ~& `
- back.setVisible(true);0 `& y+ y& t* F4 p7 j# k
- Mp3View.this.remove(mp3TVShow);
2 l9 P. h: e) n. l - Mp3View.this.repaint();
' q& E/ a- v0 u - l_text[0].setVisible(false);
+ V$ E3 \% ?2 t: G' {! }: i( ` - l_text[1].setVisible(false);
" W( H# q6 \% M6 W- e - l_text[2].setVisible(false);5 w) g# @4 Q2 w5 n
- }else{
& @" @) M: q% B' s' f - back.setVisible(false);0 ^. s! S: [7 R, J4 z: I
- Mp3View.this.add(mp3TVShow);8 P, J: W# ?- j+ Q& x/ t' n
- Mp3View.this.repaint();, H$ e5 x: K( D1 _7 M* g
- //currentMp3.getPlayer().setTVShow(mp3TVShow);3 _/ x! u3 h! I! n4 p) j' M( _
- l_text[0].setVisible(true);
% m1 i; s) h( `6 Q) l0 b+ W - l_text[1].setVisible(true);
' u/ k- q9 i+ T9 a8 e - l_text[2].setVisible(true);
! L# m4 S y. Q6 T' z* y4 ~ - }
: I. }) O! M: R; Y5 Z, t3 Q6 Q - }
8 s$ `9 q4 |/ V& j( X( i+ o4 V( ^ - G( D0 T) r* @) i0 U) I% c; J! Y
- });, h' Y/ d$ Q6 h" h- y
- }8 W( D; u1 W; {2 {- }0 Z: J
- return checkBox;0 \" [1 [* `& u! w ]; k6 {( d; |
- }0 _* I3 a; y$ Z
- private void initBack(){
0 `6 g; u0 A: w" Y& ], M - //添加歌词显示& F8 T( }9 A7 r/ K6 X; G! @/ V
- for(int i=0;i<9;i++){
) r9 ^7 R, p% X' \+ i1 d+ _ - l_texts[i] = new JLabel();
4 r p- }( K+ } - l_texts[i].setHorizontalAlignment(SwingConstants.CENTER);
8 W0 o# ~) ~ k) w" G* u - l_texts[i].setBounds(50, 20 + i * L_WIDTH, 200, 20);/ n8 W- R! F( N5 e2 o; \
- //l_texts[i].setText("hello world");
6 p, @. X1 h6 p& b; n6 t, m - back.add(l_texts[i]);% K7 u# r. {* Y0 ~- Y' T- h+ Z4 q7 g
- }+ s5 V$ {: W P {8 X& J- l2 y+ r
- ! ?. Z F6 t# ~ T E. P0 r
- 9 m5 \) q- }, q
- }2 q1 u% I$ I- U' ^! J
- private JLabel getNameLabel(){' w# m8 N) M* V" `* V
- if(l_name == null){
) C s9 V3 s7 C0 t! T( I, J# h - l_name = new JLabel();
1 U0 O7 f/ J9 y& R1 f - l_name.setBounds(150, 25, 100, 20);, K* @* K% I8 N& G, L! L. w- X c
- //l_name.setText("hello world");
- S% |5 y& J$ _1 @+ z; B2 p2 N s - l_name.setFont(new java.awt.Font("Dialog",0,14));$ p$ N* V3 k! R3 G" N4 a
- l_name.setForeground(Color.white);1 o1 x% o+ f) Z
- }
. H9 Z4 m! C: H( Y - return l_name;6 V7 q. n3 Y% U, j* e6 r- ?2 q* w
- }
+ @8 H+ B5 p% E7 c/ G1 H) R K% x - private JSlider getProcessSlider() {6 M i; T! r+ ?1 e. |, W) ~" G* W
- if (processSlider == null) {9 `( K$ S# i8 j! Y: k
- processSlider = new JSlider();' }6 k a' i9 @3 i5 F# D6 U- t3 q! J
- processSlider.setBounds(10, 40, 280, 20);: F: y" @ K* R7 F6 s# ]% U, n0 B
- processSlider.setValue(0);
& A: s; c$ ?, S% f7 J2 Z: B; a9 }% m - processSlider.addChangeListener(new ChangeListener(){
; x, s( U7 U% W/ J
1 k* Y( h2 J# `. e! f- public void stateChanged(ChangeEvent e) {
; E, ~4 v+ A6 X6 k( F& q/ p, N2 B - textTime.stop();4 L+ r9 V: y( P' R/ N; r5 n
- if(!processSlider.getValueIsAdjusting()){
& B. L" ~& x. i% x- U$ O - - \9 J( j D8 a/ ?9 X) m w
- if(progressSliderDrag){
. B, J8 u: }3 Z4 C6 e4 v - progressSliderDrag = false;
+ V1 i' H; R! T+ g9 v7 U8 V - double rate = processSlider.getValue()*1.0/processSlider.getMaximum();
% n- P0 \8 z- G k+ Y3 b, K - currentValue = processSlider.getValue();" D9 k: P0 o' O
- currentTime = (long) (currentMp3.getPlayer().getTotalTimeSecond()*1000 * rate);5 u, {, ]) |# I' y2 u- h) G& `
- currentMp3.getPlayer().seek(rate);% h3 ^, q8 P$ o# B- \
-
9 J5 m2 z& r% k8 D - }
! |& x4 M7 v$ Q5 ?) o/ [, u5 k+ S) Y - }else{
) L) M: Y; s3 w - progressSliderDrag = true;2 `/ Q' s+ }( P4 x3 q: n* U
- }
3 ], M$ C9 R! d. W& t1 H3 g - textTime.start();- E3 A1 a% l5 n* y- q
- }
9 y( H3 h: S H -
1 U+ a, E! Y, I - });0 C. U- E& b' x7 F4 ]
- }0 F0 x& p/ l8 C3 D
- return processSlider;
! U: p0 o+ F1 c0 Q7 h0 N% S - }! `* n- |" I9 V
- private JButton getPlayButton() {
: |) D# Q! s' n. q' i - if (playButton == null) {0 B( g! |: J5 k
- playButton = new JButton();8 F* M3 i6 S% C
- playButton.setBounds(150, 65,60, 20);
) V; S. H$ v7 v k) ~& q1 M q8 Z - playButton.setText("播放");
7 E2 T/ o: R8 P- k4 I/ Z - playButton.addActionListener(new ActionListener(){/ A7 J. U, ~+ J: z
- . @' a1 _. |; l. m q+ n
- public void actionPerformed(ActionEvent e) {
/ T- c x$ C' ?! l- \ - dealPlayButton();- ` j+ U4 v) |! J1 I; }# f
- 8 \9 n8 \, G W6 L* k' }
- }
! Q* T' b- ?5 G3 O
4 v+ K. X& w" ?- a+ Y! `: U1 l- });
& G3 U3 O/ S3 N0 p* e - }1 c+ J" [& w' `1 [
- return playButton;
* |0 ^- W$ Y( T5 w5 w5 L - }2 Q5 f0 Z) ?; z3 l
- private void dealPlayButton(){5 n1 m. s: ]- W+ N8 [0 D; q# D
- //currentMp3.getPlayer().setTVShow(mp3TVShow);' X" n% ?2 Z' @1 q" ?
- if(currentStatus.equals(Mp3Status.PLAY)&¤tMp3!=null){
* k5 Q2 ~5 g: k O. q- `9 T; W/ A - currentMp3.pause();1 H5 ^3 l, n6 p% R2 a3 c( B" g
- progressTime.stop();
! n" \! z& a0 w% p6 B7 h - textTime.stop();, B. p) I6 ^9 p
- currentStatus = Mp3Status.PAUSE;
- y0 ?# g S* M7 K j - playButton.setText("播放");9 E+ y$ d: r" M" ~
- }else if(currentStatus.equals(Mp3Status.PAUSE)&¤tMp3!=null){- P$ _* L9 u5 n, o
- currentMp3.goon();9 G5 `4 A9 m8 |: I9 D3 m
- progressTime.start();& G! d) b& a1 n" n
- textTime.start();4 y( j! R3 x. y O$ g
- currentStatus = Mp3Status.PLAY;
* e7 x: w* \6 T1 ? - playButton.setText("暂停");$ X. p6 l! H2 I0 s" T3 {
- }else if(currentStatus.equals(Mp3Status.STOP)){. P* x4 B( ? l4 c2 N7 L6 O# E
- playCurrentSong();
/ A. w) g+ t% X) b/ b5 i) a - currentStatus = Mp3Status.PLAY;9 M/ N2 [5 g* a/ |! \8 Z+ {
- playButton.setText("暂停"); ^9 I: N5 z$ t4 s
- }
3 c& ~& D \0 L d - }
* g+ w) t0 d$ n - private JButton getStopButton() {
5 g& [* @& |0 M0 ~ - if (stopButton == null) {, S) e/ j6 p! t6 |: \
- stopButton = new JButton();) L9 g5 Y# R" L- e6 a6 J4 N, |* @6 @
- stopButton.setBounds(20, 65,60, 20);
+ v5 ?: O* y! S5 U& A. g) `' x5 w - stopButton.setText("停止");
7 y7 V) O- }+ s. H. u& ~) y - stopButton.addActionListener(new ActionListener(){% n0 O$ y& P; q/ F
- 8 }* q9 P/ A% c4 g. r$ G' n! |
- public void actionPerformed(ActionEvent e) { ! }0 F9 @7 |; {# ^+ Z9 |2 c1 d) L
- currentMp3.stop();0 o, D0 q+ |0 H, ]
- progressTime.stop();
& E: Z( r& Z; I8 O! o - playButton.setText("播放");
5 k/ e+ Z% |, u3 I+ @ - currentStatus = Mp3Status.STOP;# ~. I) F) a5 @3 ?/ b4 N$ q# C
- }
, Y p2 `! a0 ^# I. Y - $ k5 \) y4 {3 j
- });
& J6 G6 r+ i3 o. M$ H - }6 E, E4 B! n+ K8 ]+ z+ S% S- a
- return stopButton;$ ~" e$ ^5 \4 g2 A0 l
- }' i! F) Z5 r5 l" N+ q0 @6 ~
- private JButton getUpButton() {+ _( R, |# O9 }5 Q! e
- if (upButton == null) {
& D5 h2 v% V9 B - upButton = new JButton();
7 b, z8 C5 [' }% c5 Z# i - upButton.setBounds(85, 65,60, 20);
$ k4 b" \0 g; R5 t: d - upButton.setText("上一首");
" u5 i0 Y. B- X0 U& e. H! I - upButton.addActionListener(new ActionListener(){
5 U [/ H' `) o8 t -
8 u* s5 [& p7 ? - public void actionPerformed(ActionEvent e) {
1 v$ O7 k8 d' m- P r4 r - int currentIndex = list.getSelectedIndex();- b4 Z& J% W- S( J6 |' [
- if(currentIndex>0){/ w9 a. C" x+ O9 c) ]; D
- list.setSelectedIndex(currentIndex-1);5 T+ J5 P9 B1 u8 [% f
- }else{+ a' m" [4 f& N% p& }' S
-
$ \' W' i7 Y3 v& ?( L- j' X - }
0 [7 j) S% f5 M6 O9 |& | - playCurrentSong();( _! r, t9 [) C) I
- }
2 }/ _2 [6 U# Z" J - ; \1 v/ W8 _; [/ F% B& H
- }); F' a0 m* }" Y; b
- }+ I2 V3 R% H5 r! o
- return upButton;
% }9 _; o$ u% n/ m, U3 b - }+ R9 O' {& D% F$ }: I& c, [
- private JButton getDownButton() {" u* D) R& q5 e, g
- if (downButton == null) {
- _, y9 M9 A* M/ {7 ^ - downButton = new JButton();3 a* v6 c. g: u7 d$ I$ I
- downButton.setBounds(220, 65,60, 20);
& r& Z" Q% r( e3 A* `4 x& X - downButton.setText("下一首");
' _9 `3 [6 E/ T& h1 S - downButton.addActionListener(new ActionListener(){- P0 ]! r" [# h/ X, Q- n& ^4 _
- 9 o. I" P1 Y. M& x) e4 R5 d
- public void actionPerformed(ActionEvent e) { % c7 |5 F a( L G! s+ e
- int currentIndex = list.getSelectedIndex();
$ X8 c9 l; h3 u1 s+ M1 K - if(currentIndex<(lists.size()-1)){1 i. v F! H* o4 q
- //currentMp3 = lists.get(currentIndex+1);
3 ~! {, V) |/ V+ ]7 E. y8 g% i - list.setSelectedIndex(currentIndex+1);3 `. i7 c- K: G: c
- }else{6 k! k; ~0 Y q
-
" W8 i# l. _9 W/ c: Q$ R - }
0 `$ X% x/ K4 w8 D7 k# U - playCurrentSong();6 y" W4 c, t2 u3 p: `# w- Z1 V
- }4 N) G! c7 C- @/ D
- # D; o/ j7 f" U5 e! N
- });' P9 h. {' C$ W) @# C: h
- }/ ?( J0 Z2 x/ R% ~' @9 b# A7 @
- return downButton;
# o) g8 o, Q* s% I6 f6 I7 a - }$ G$ N: }' [* ^0 g. h
- private JButton getAddButton() {( E, ^" W+ ~2 K4 _
- if (addButton == null) {! @( d& {* y9 Y' o
- addButton = new JButton();
. T$ Y8 G, I, y8 ^ - addButton.setBounds(60, 530,60, 20); D# p9 F4 X& O. }
- addButton.setText("添加歌曲");
7 K2 Z" n& g$ L1 y( V4 W5 d3 } - addButton.addActionListener(new ActionListener(){( z0 l5 r8 \# ]! A/ t9 v- ^
- 6 N9 n( w9 b# ^6 O: y( u6 n
- public void actionPerformed(ActionEvent e) {
# p p* @) h: X1 K' F - loadFilesByJF();8 g0 N$ X1 Z9 f. V2 U4 P o9 H+ N
- } ^6 `% t5 J/ b5 P3 S
- , \7 N& G+ g/ w0 J' W# B
- });
0 \2 d) N5 Z1 p" v - } l- \2 O. x |3 g, F; n- m/ O0 d1 q
- return addButton;8 b9 R6 H' R* l
- }# m0 c1 B s* Z/ j" F- v
- private JButton getDeleteButton() {# _- T/ o9 M$ Z* Z9 i
- if (deleteButton == null) {
0 j7 m8 z9 U4 T; p9 R7 t* w - deleteButton = new JButton();7 `' C: s- Y* v: r* O8 V2 s/ g
- deleteButton.setBounds(160, 530,60, 20);
- p/ E7 m( Q# r$ h& @4 t - deleteButton.setText("删除歌曲");
, F% m9 F8 |+ M; x1 Q" ` - deleteButton.addActionListener(new ActionListener(){: m9 J5 o4 c( z1 q9 J/ e) d! A* r
- $ X( l! q" q7 h/ @
- public void actionPerformed(ActionEvent e) {; `% Q1 J6 w1 N9 \, x# }
-
+ n7 d6 w' ^% c O0 E. z, L- q- m - int index = list.getSelectedIndex();
4 F& W, D/ h5 {4 q: p) j - if(index >= 0){
: E; Z" ?5 s$ c% L" O. x S6 C! ` - lists.remove(index);
. ^3 B- h: `; _! X! j$ L; O - model.removeAllElements();
* D! F# p" e% t: G - for(int i=0;i<lists.size();i++){
7 G9 w5 ~& h' o6 o# b - model.add(i, removeIndex(lists.get(i).getFile().getName()));7 m# M8 D" ?& u/ |& K7 y7 L$ Q8 Q4 n
- }
) ?' P/ d% J- w( p" w/ U - list.revalidate();
" |& r: p" Z+ e `' ?+ `+ x - }+ ?$ X9 W5 r% ?1 [9 Q: Z0 ]
- 3 Y& O# h' C& o( Y) t7 X; H- M
- }9 y, t+ N8 Z' x& `7 c- j
- 8 B0 h. t5 l& n" j
- });
8 y8 H! e3 {0 B% F - }( {: C5 u# n# [' |& b/ C8 I0 H \
- return deleteButton;$ s6 Q& J: S0 r+ ?9 I
- }# c9 J0 n& g* W) q F, N
- private JSlider getVolumnSlider() {
# X0 ^3 W# X. @- |9 x& j& E - if (volumnSlider == null) {9 r$ V. K+ ?9 y o0 r* \( L8 \
- volumnSlider = new JSlider();8 W, s) O. G3 z& x
- volumnSlider.setBounds(200,90,80,20);, [3 C3 b9 `: f+ n8 ~$ Q9 _
- volumnSlider.addChangeListener(new ChangeListener(){
3 X# {! e, j7 [: s5 ], [0 k/ N
! \/ Y+ V2 i6 F' Z: t7 [- public void stateChanged(ChangeEvent e) {3 y ~$ ?3 B, ~. [8 m
- setVolumn();; ?6 U/ {# e6 `6 F
- }) F! I* F! f, p9 C- I. q
-
' `- W \9 ]1 `7 A - });, U- R: f8 Z# z( J4 u) A
- }
+ C5 n. n( s8 U- n) |# T - return volumnSlider;4 y- L8 r: m* n' `# n2 B- T, a
- }
$ b) G }9 L' U- B! R# D4 d - private JCheckBox getTranBox(){
& ~3 a) C% F4 s - if(treanBox == null){3 j- U5 w6 O7 Q
- treanBox = new JCheckBox();/ p7 |2 e/ K8 \7 B6 \; U% a
- treanBox.setBounds(20,90,100,21);
^6 V0 w* f3 s: d; g$ [/ H - treanBox.setText("单曲循环");) g s' a; P* I5 f$ O
- treanBox.addChangeListener(new ChangeListener(){
' H" f2 |, m" w$ t. L9 ~: w8 a* o2 c - public void stateChanged(ChangeEvent e) {9 U& r# p' D8 s$ K
- if(treanBox.isSelected()){
' F3 Q, g" a+ Z8 G0 o9 ]0 Y - tranType = true;* Y- I1 L# b) w: p
- }else{& f' Q+ C; m* M2 t7 s" L
- tranType = false;
" V- d! ~/ E' y7 t5 {* h - }) Y% i/ @6 M& {0 b
- }# |# L, I* v; { q
- 1 v$ Q* V: Z5 G( p5 j& ` I
- });% I: x+ S0 C$ U& O A2 n
- } O' H6 A N+ ^7 K2 K, M$ N
- return treanBox;8 f9 G, i2 ^9 _: q9 G$ F1 s- [
- }
- ]- W" D% S0 D, ` - private JCheckBox getMuteCheckBox() {& R; y+ T. x9 W. \7 X- a9 B
- if (muteCheckBox == null) {6 f6 D4 v( f# g, w8 y# J4 ~ X
- muteCheckBox = new JCheckBox();
- X( r/ z4 \( a% [& N& [' _ - muteCheckBox.setBounds(280,90,60,21);
6 B; N; {/ s& B: q2 D3 W - muteCheckBox.setText("静音");
& O; t% i( M' o& }2 Z - muteCheckBox.addChangeListener(new ChangeListener(){
, e9 I2 N! @) R/ S& G4 |
$ h7 Y! _2 X3 g- U! B" k3 z+ L- public void stateChanged(ChangeEvent e) {
# I5 [5 @, ~2 l: H* q6 q - if(muteCheckBox.isSelected()){4 c5 m/ O" O* u+ e0 H- H" Z
- getVolumnSlider().setEnabled(false);' h8 d8 q2 _& @7 y @; w
- }else{
9 O1 [3 }: r3 V8 z - getVolumnSlider().setEnabled(true);. i( M4 A c. n+ \' U4 Q
- }8 o- e" b9 c% l |; ^0 g3 d
- setVolumn();
3 O; m/ ^8 M/ t" ?5 j, ] - }
; m- Q1 w, U1 w9 G7 I -
; J% \* K0 w% ^+ e5 Z5 _ - });0 _! n3 Q& \4 J: Z( s
- }( F+ O9 i2 _7 x) \8 ^7 V; i& S
- return muteCheckBox;# o8 ~* d$ t3 f1 e% d7 ]8 T
- }8 \+ Z( ^% n6 {) R/ s& o
' ^5 k* ]5 {' L. }: d7 E% K# s1 r- private void setVolumn(){
% k* ^6 H ^% ?6 d1 Y1 g5 t - if(currentMp3!=null){
! l4 |2 @% t' m$ v* Q1 n$ {/ s - if(getVolumnSlider().isEnabled()){ $ d1 e' i% o! E1 Z# S
- double gain = getVolumnSlider().getValue()*1.0/getVolumnSlider().getMaximum();; h* X' L+ O4 A: O
- currentMp3.getPlayer().setVolumnGain(gain);) n0 \9 G+ `+ f$ k. @1 K
- }else{/ Y( e# Y) x7 X' p7 C: O9 k
- currentMp3.getPlayer().setVolumnGain(0);* [9 e* J' F. J1 [8 [+ |# s% n; m
- }2 |, W p( \, V! l1 ] O0 c
- }
# y) B- s7 z% G: T0 s - }" N6 v6 C) ]* h; K& q
- ' q8 K( h! r3 J6 h- F$ |; P. j# a
- private JList getList(){
9 f/ p6 `: d9 S1 A5 h( o7 @% d - model = new DefaultListModel();/ ~ G4 N& M2 ]0 F
-
9 B0 L* {, V8 n' i& |( P/ ] - if(list==null){
5 a- P' F+ v9 u! k6 } - list = new JList();5 W, K1 C* Z5 l9 {5 {
- list.setModel(model);
+ K* z3 z# u4 M0 I( A! Y - list.setBounds(15, 120, 300, 400);$ k: s9 v7 I0 T3 V- K/ x
- list.setBackground(Color.white);% y8 \3 b1 i" Y# E5 M t
- list.setFixedCellHeight(20);/ _ B( f" c' C
- list.addMouseListener(new MouseAdapter(){+ @2 b! M- l. n( A5 n1 _# _
- public void mouseClicked(MouseEvent e) {- u; D4 E# G0 b$ }5 _2 N+ s% k
- if(e.getClickCount() == 2){
) V- X q! i2 P - dealPlay();
+ _: t' U8 f4 x - }
2 [2 `0 x- x% q# a i7 k - }
2 Z3 f3 {* X0 G; a0 Z/ \ - });+ Z& P, e1 G8 _5 y, s
- }! l4 K; K0 n2 A' }' Q
- return list;( W( s+ i1 S' n( u
- }8 ^% I9 j, J4 }2 |, V6 }
- private void dealPlay(){
2 t% Y5 E& x( b* ~1 ^7 O7 @! O - playButton.setText("暂停");% Z' C; Q. r& B# K. x
- currentStatus = Mp3Status.PLAY;6 ^2 a6 P0 N: Y$ O# C' R
- playCurrentSong();% b! A8 m) O3 t0 x4 d6 [' `0 V
- }
7 b# S- e* k( h+ q( X% } - private void playCurrentSong(){
! u, M5 l7 K9 U( v! z& m - if(currentMp3!=null){: l l/ ]& Z1 ]* V1 t
- currentMp3.stop();4 M0 l- k7 m0 u; @, Z
- currentMp3=null;
: i+ X6 \2 g3 q1 { - }
) o! c; A# E' B6 G0 H' U -
" L0 C/ L) X) v) D+ Z - if(list.getSelectedIndex()>=0){# D! _0 S1 O+ F/ h Z6 [
- crrentList = list.getSelectedIndex();
* {' ~8 d+ d M2 ]8 V3 n - currentMp3 = lists.get(list.getSelectedIndex());
- o/ O9 s1 c( i, F: H, \! @ - currentMp3.getPlayer().setTVShow(mp3TVShow);
" ~& o7 T0 a$ ]# s* } - currentMp3.on(); k# t. z- B' W3 Q2 c
- l_name.setText("");. O4 z5 h! Y8 q0 \6 ?0 K; s
- l_name.setText(removeIndex(currentMp3.getFile().getName()));
9 R& C f* |# m% G8 C - //处理进度条
, d7 H+ y' u* w P N - currentValue = 0;$ s' {" K- [( R9 W2 m, R
- processSlider.setMaximum((int)currentMp3.getPlayer().getTotalTimeSecond());$ Q# u% D5 y* Y1 W3 ?$ t# }
- progressTime.start();: p+ u- L( h7 r8 G f7 F: p- s! p
- //添加歌词面板; U2 }6 m+ A! C7 Q( _( d
- if(back!=null){
! y/ c) x" {* X2 c' g - back.removeAll();+ X/ Y. N8 a/ e9 p0 H- ~
- this.remove(back);
9 h' h5 O& Q. P2 D8 C9 B! {) F& V - this.repaint();# I) a" |. a& M4 C# S7 V1 N$ A6 _- {
- back = null;
; _5 v- h4 R1 s# D9 ] - }7 \2 E+ Q: U2 W+ d+ g2 L, H! V! O
- if(removeIndex(currentMp3.getFile().getName()).equals("千里之外")||removeIndex(currentMp3.getFile().getName()).equals("菊花台")||removeIndex(currentMp3.getFile().getName()).equals("双截棍")){
( E5 U1 R }: I9 q - back = new Panel1(1);
, O3 J; v* Q$ p& b: {) w0 J) F$ |" o) Y - }else if(removeIndex(currentMp3.getFile().getName()).equals("为爱痴狂")){- z0 |: [3 D* {+ ~+ s5 S
- back = new Panel1(2);0 W! [( x1 a" R: ?4 t& [- @
- }else if(removeIndex(currentMp3.getFile().getName()).equals("荷塘月色")||removeIndex(currentMp3.getFile().getName()).equals("最炫民族风")){- O0 z9 y; F- O5 w4 J
- back = new Panel1(3);+ ]% f' l& `) w- ~2 W
- }else if(removeIndex(currentMp3.getFile().getName()).equals("六月的雨")){
h2 T5 x- q! t! S' i& n* r - back = new Panel1(4);
: p2 ?! ?' Q' s: I& x8 u# W - }else{
" u6 e0 H: Z1 y - back = new Panel1(0);
% i' Z$ Y3 g( `$ K; R4 [ - }
! \- ?( L0 n. I - back.setBounds(370, 120, 330, 400);) _; A) L9 x8 ^2 B3 B
- //back.setLayout(null);
# i" x( u O) z% F/ k - back.setOpaque(false);1 [4 X# S$ @* l) {
- //back.setBackground(Color.red);
9 g2 j% _/ X } - initBack();$ ~) ?' m" D* i3 ]# g, l( `5 D H1 q
- if(checkBox.getState()){: [7 y& v3 T% I0 m& a9 ?" ~
- back.setVisible(true);
5 T9 j/ {1 j, ?# i6 s8 y6 \3 v - }else{
( L- U) Q# b9 Y S( u" ~ - back.setVisible(false);9 H% w- ~, ~5 Q1 P
- }
5 b" w0 r7 c" M* ~7 F& O. G - ( I3 E+ F; v% b9 Y
- this.getContentPane().add(back);2 l$ z* \6 B( h7 k6 D
- 2 o7 f9 }/ Z9 } ?) i- M
- this.repaint();0 v9 v; J! G l/ [! `! G# S
- 4 X, x. s, C& p0 @0 [9 h
- //处理歌词, s3 \+ d$ l% t$ Q) U
- if(textTime!=null){
- ^; v3 Y& ~6 G1 l - textTime.stop();2 @: Z5 C6 }# E
- }
' [- A' i8 c* g! |7 w" B - for(int index = 0; index < 9; index++){
9 {9 V# _+ D& p8 s - l_texts[index].setText(""); }: M) n) I4 g+ a) I W
- }1 S: q" O2 q5 h5 o5 @1 W" H
- for(int ind = 0; ind<3;ind++){* @1 N! F9 R( w; L+ d6 }
- l_text[ind].setText("");% A( |1 R) r. H& o2 t- s
- }4 ~1 d4 y+ }( K* b6 _1 t
- if(currentMp3.getMessages().size()>1){7 v8 p) o! E: D- I/ O, E
- 2 A5 Y& k! U% o9 ^) k. J
- times = currentMp3.getTimeMills();
W9 K: M& ]) y -
# o3 z9 x5 d Y, c2 \ - messages = currentMp3.getMessages();
% b" W3 A; b1 |. S, E - currentTime = 0;" J6 S3 B/ G1 R4 S
- textTime.start();
' [$ f+ c8 D; B m -
3 J' `+ k) ?" X9 r" i, D - }else{
" n( S% s$ i6 t, \* q3 a& | - l_text[1].setText("该歌曲暂无歌词");
1 c# ?- j; x) C; W3 w1 r - l_texts[currentLocation].setText("该歌曲暂无歌词");# c% G8 _6 G) N# G4 h, f M! |
- }1 P7 O- r3 W9 x; B5 p, g' l# ]- N4 \
- , t% g7 r& a/ n9 [' _
- }% \* I' |( x" J( }
- 8 M3 F( g; W/ V- E* `! n7 U1 a* @" Y
- }1 W4 U; C4 x) b0 v! X+ e% {0 T Q
- private void loadFilesByJF(){+ L& p6 X; W, J9 M3 k
- JFileChooser chooser = new JFileChooser();0 U9 j) u0 T( L4 v
- chooser.setMultiSelectionEnabled(true);
- o3 h2 C) c! j" z' Q - int returnVal = chooser.showOpenDialog(this);5 W+ h- m5 z0 M( A7 z+ ~8 u9 S
- if(returnVal == JFileChooser.APPROVE_OPTION) {! D0 d$ i7 t! w/ s2 z& l
- File[] selectedFiles = chooser.getSelectedFiles();$ y, d* R6 x: \! l6 t6 H0 }
- control.add(selectedFiles);
0 T7 w& q$ p4 M( W - lists = control.getMpLists();5 W3 p& d) v! _$ M
- model.removeAllElements();
: Q8 C1 a( G3 ^! z# g% {& @ - for(int i=0;i<lists.size();i++){/ D7 T, Y/ }' ?$ V
- model.add(i, removeIndex(lists.get(i).getFile().getName()));
* T; s" V& L; ]; Z& R o4 ^" h - }5 L/ y! t) T$ q
- list.revalidate();& T" g" P( ]8 D' ~, K
- list.setSelectedIndex(0);
# z0 P9 i) S+ e- x9 Q& U! d - if(currentMp3==null){% }$ C$ m1 I$ ^- W" P3 e
- currentMp3 = lists.get(list.getSelectedIndex());
6 G p6 a3 x- X' G - }8 d$ b+ l& Z& `
- }
4 b2 f5 \# N. j& H4 s
. A: j! k6 T% t9 }. H! m- W- }
; n2 y! t! W# G% L2 ?* j+ L - private String removeIndex(String name){- z* n( y# U- T& E& V
- int ind = name.indexOf('.'); Q! C+ s* B4 ^0 ~/ ~( f1 Z
- String child = name.substring(0, ind);
2 q7 V( g4 {) }- V& |9 O- O - return child;. m$ F! F' {5 @' }* i* N2 `
- }9 U8 Z1 W) S3 c0 v* N" S) ?
- class TextListener implements ActionListener{) A9 M/ v; k8 |/ f+ k( m/ J
- % Z+ M4 V0 Y8 D
- private JLabel label;
% R) ]* s7 J1 a& B# }/ | - int index = 2;
8 S) N- h' T0 @1 Y' `" y - public TextListener(JLabel label){/ I7 b2 b6 i& ~' G" I
- this.label = label;
, o- y. n5 A+ V- ? - 9 I" _. b2 B4 j. C8 r
- }
" N1 C) m# b. u: V6 @4 _+ t - @Override1 d; W$ k7 `! j5 q% ~# f. q! E6 l* o
- public void actionPerformed(ActionEvent e) {
9 N4 _( g6 t* z* _0 }, X1 ], k6 Z - // TODO Auto-generated method stub
+ X; V* {+ X5 j - label.setBounds(100+index,22,150,20);
, ^3 K. R5 }, l" ?, Z, o, q - index = index +3;" z4 X0 ?8 e, t. c
-
. b2 z* M% q7 z3 f: V# E. B - if(index > 150){
& j0 P! m" o+ E( T* t0 Q0 p% o - index = 3;8 I1 Q O0 F' }
- }. t/ C0 |- E( d. r
- }
5 H2 ]: a3 Z$ v0 Q0 I7 G -
; g4 H7 k7 z4 \ J - }5 J [4 _$ ?; |: m$ i/ _ e5 ^, D; F1 o
- class MyListener implements ActionListener{% P! v$ V* d+ {2 p& r; m2 G/ B, K% ]
- ! z; f1 a* s3 C' E" |; `* B- y
- private JSlider lider;
! U8 x2 t3 m, p2 I$ A - public MyListener(JSlider lider){% B8 Q% l+ D. Z5 w
- this.lider = lider;4 d- i) ~* g# c8 _ {
- }
9 r, ` @+ Y; }# }" y - @Override* n* ]# b9 V7 U) a8 I6 ^
- public void actionPerformed(ActionEvent e) {
& m, O! n1 m& h( R - lider.setValue(currentValue++);2 t2 {3 t& F% ?- x6 K
- int minite = currentValue/60;
. g1 g- ^7 Y- k - int seconds = currentValue%60;
4 ^, v) R% f; T4 S7 G, W2 l - String second = "";
) K; X- B; X+ z1 y! `5 j5 h" { - if(seconds>=10){- y' P, j) Y2 `
- second = seconds+"";
: P+ t! v5 s2 ^( z- G0 L! k - }else{
' G! t# H# \: `; V - second = "0"+seconds;. k1 w/ c( p( x$ `- H9 G3 |
- }
! s6 i; |6 G/ j. a7 q - l_time.setText("0"+minite+":"+second);
k' i q" \% C1 `3 E) } - if(lider.getValue() >= lider.getMaximum()-1){( _$ j6 D. i) e _9 |9 z* e
- //int currentIndex = list.getSelectedIndex();
8 e1 ], U# N) m- C% | - if(tranType){6 U! D% G6 d% [# @- c' s
- list.setSelectedIndex(crrentList);
+ t# A6 O5 P- T/ V/ z5 r, x/ J - }else{) V* `( O8 |2 Q$ D4 M1 C
- if(crrentList<(lists.size()-1)){# L5 d! F0 L! N' I8 Z
- //currentMp3 = lists.get(currentIndex+1);* @0 w% u: a+ G6 d1 {; C& ~
- list.setSelectedIndex(crrentList+1);* l7 c! U. W5 [0 }8 N# L
- }else{$ I: {0 u( R8 k# j; y7 h5 O6 G7 U; E
- list.setSelectedIndex(0);, [8 l7 S+ u3 ?2 y* j8 J- G* y
- }6 S0 l( n7 y: M- a
- }
0 {, R" k6 Y# B/ J - + ~* v; ?) W; [* V" Y$ U |
- playCurrentSong();
2 ? P) i2 ?1 _1 W/ H3 d - }7 G8 o% N; A" D6 T
- }$ |. P" K9 p) c' `. ~
-
/ k& r8 C- b' x - }/ G& S7 k. t, J) r( x
- class LrcListener implements ActionListener{+ _# [; G9 [" |2 D" c; x+ X
- * D m. r% S) R) J! Z( ?% }- Z$ O
- private int i = 0;3 S" t3 @8 k3 K4 C; H1 P n
- private long nextMill = 0;$ p. S8 `. `5 }0 A- D
- private String message = "";
M. X( S# c- s# D {, M p - public void actionPerformed(ActionEvent e) {
: b2 Z3 a: ?8 r: T/ U% g' {1 K5 f8 K - 6 E( J( j! L$ a4 }9 y! ^& P
- for(int j = 0;j<times.size();j++){% W4 |' A8 M% h' ]( {
- nextMill = times.get(j);# e% `4 P# k4 E
- if(currentTime < nextMill){
" F5 j5 I) W4 ?2 [6 u8 B4 x - nextMill = times.get(j-1);
1 c9 {# s' } C+ h$ Y - i = j - 1;
" \! n' d0 Q2 ^" R$ M* z - break;; G" d# p% n, F
- }: R% W/ A+ N: i* T3 L
- }2 J) w% x% d8 f4 ~
- currentTime = currentTime + 10;
. _; Q; Y' l/ {6 Z i9 K( i% y, p - if(currentTime>nextMill){7 I3 r6 j0 D5 r( V: j+ c+ k
- if(message.equals(messages.get(i))){5 s7 O Y' ~' ?8 g2 l+ M2 O
- }else{ s0 s# A6 k: l* H5 q' }
-
' m) }. \' U/ K# L' x3 y) @5 t - for(int a=0;a<times.size();a++){/ h3 B1 D1 ~ }/ I/ Q- o% c
- }
- ~- N/ N: e# u: s - message = messages.get(i);
5 H; x: [ |4 y# P+ Z! D - System.out.println(message);( q6 v3 G9 u9 ^5 h% ?$ j
- for(int index=0; index < 5;index++){) @: P, A" ^9 y* o
- if(index == 0){
$ P% P2 ^8 n# U - l_texts[(currentLocation + index)%9].setFont(new java.awt.Font("Dialog",0,22));: [/ L! n8 d: o# o( i
- l_texts[(currentLocation + index)%9].setForeground(Color.red);
$ x5 T+ r' D' R8 p7 u0 c - l_texts[(currentLocation + index)%9].setText(messages.get(i + index));
) T% l( m' o2 ]3 l- ^, j - l_text[currentLoca + index].setFont(new java.awt.Font("Dialog",0,22));6 _% t3 p/ E5 Q, E% l$ G
- l_text[currentLoca + index].setForeground(Color.red);7 p9 m1 ]2 h4 d; K y
- l_text[currentLoca + index].setText(messages.get(i + index));- N. x( P$ M/ B3 R4 ? D& ?
- if(i>0){
! @+ |$ V& V9 b2 ~4 N/ v - l_text[0].setFont(new java.awt.Font("Dialog",0,16));
4 o- h' W u7 A- i& k2 w6 h - l_text[0].setForeground(Color.white);5 d2 a. U! M) T2 R6 V
- l_text[0].setText(messages.get(i - 1));
: S/ f# M! v1 p8 T - }
1 E! z7 \0 j; A; T8 E. t3 s - if(i<(messages.size()-1)){1 U( j% f7 v" z2 w Y
- l_text[2].setFont(new java.awt.Font("Dialog",0,16));' S6 C3 G# k$ c/ p2 q, S' C
- l_text[2].setForeground(Color.white);- j4 w* ^7 m# F) ] Z0 T
- l_text[2].setText(messages.get(i + 1));/ [4 p+ i. `/ H+ I% A7 Z' x
- } m8 E/ [ q1 w" e# {
-
7 C6 f/ Z0 g$ Z1 j: W - }else {
) Q0 J6 I8 _ O4 K! n - if(i+index<messages.size()){
* r2 |: F& y3 P9 q7 X+ W - l_texts[(currentLocation + index)%9].setFont(new java.awt.Font("Dialog",0,16));
7 ~9 j( e; B: [% I( j; X - l_texts[(currentLocation + index)%9].setForeground(Color.white);: r3 U) }3 f& C. p7 w
- l_texts[(currentLocation + index)%9].setText(messages.get(i + index)); n& Q1 f+ Q2 o4 i$ u. l% e
- }else{
; X; g7 A3 V2 Q8 x1 h6 Y$ L - l_texts[(currentLocation + index)%9].setText("");
8 V9 e& V# c. T5 g - }$ c5 c% o4 b' h* D4 M5 g. f+ H
-
( n" H* b, A/ h; w2 z - }
4 \* Z& r% P, A% F8 S3 B5 F8 _ - }
- K6 o# N- b& p* V( P - for(int c = 1;c<5;c++){9 p4 _6 u ~8 R3 X
- if(c-1<i){* t/ k1 L$ U" F6 D ]! a( L% {
- if(currentLocation - c>=0){
- x, D( p0 w7 a6 G- c/ Q - l_texts[currentLocation - c].setFont(new java.awt.Font("Dialog",0,16));
# g: d3 o& W" | F3 q - l_texts[currentLocation - c].setForeground(Color.white);
! C$ k! w0 ]/ N# f - l_texts[currentLocation - c].setText(messages.get(i -c));* u6 ^- G" h( k% L G( R
- }else{: J, B+ I3 y1 o- Q! T; g! H( w! p
- l_texts[currentLocation - c + 9].setFont(new java.awt.Font("Dialog",0,16));
7 P/ o& L" |* j; S! l - l_texts[currentLocation - c + 9].setForeground(Color.white);) c8 P% D! H5 y% m0 F) N4 ]3 u
- l_texts[currentLocation - c + 9].setText(messages.get(i -c));
! u* D |1 {: m9 ?' _ - }, H0 q' y: b* n" _. T3 v( V
- }$ ^# L7 w0 G- \5 u$ U+ ]( J
-
; Q2 P2 q7 u0 u - }
5 a' S. y9 H& W. E/ K" U9 m - for(int je = 0;je<9;je++){
q& T; Q; m9 B. ?8 n - if(currentLocation >= 4){4 C9 D" Q0 I- S2 |( f/ _: x
- l_texts[(currentLocation-4 + je)%9].setBounds(20, 20 + je * L_WIDTH, 270, 20);
1 E) l/ [+ g% X t) ?$ @ - }else {+ [' n. `4 f9 i$ O8 l4 f4 u
- l_texts[(currentLocation + 9 -4 + je)%9].setBounds(20, 20 + je * L_WIDTH, 270, 20);
1 ?& J- r$ F3 g8 z4 d; k - }
* }% l1 P7 _ d( e1 _) c0 W) L - }
! o6 a. }% w& @& ] - }6 Z& W' q1 s3 K9 z( c: [0 d
- 4 u3 U j' C2 q1 N/ @
- }
$ _9 H% H8 J: n2 ]$ @9 b( o - + J4 d" ]' q+ [, @ \
- }2 A6 w7 ^ O7 @( i! Z5 F, h
- - Z8 b) E# J Y6 {6 X$ E
- }
' U K5 w+ Z% n -
/ t; H3 S1 [, `! r$ K - public static void main(String[]args){
8 d' K3 ]" @* P. c1 G8 Q - try {
7 U# ^- H4 `! E) m - UIManager.setLookAndFeel(new SubstanceGreenMagicLookAndFeel());
8 ~( N, P& c) s) Q - } catch (UnsupportedLookAndFeelException e) {- I$ }$ |% Q1 @/ t1 N
- // TODO Auto-generated catch block
- n, V! X& c5 C% f/ n - e.printStackTrace();2 [' l1 ^! X( o' T$ J! V
- }- ]+ o7 @2 x# L2 O1 \3 d
- Mp3View mainview = new Mp3View();
7 x8 e! v( g) M1 |' e - }
/ W. Z+ ~; V+ R5 P8 C! z& T, d - }
% r7 L- w9 ?0 F* G0 l$ i* b
复制代码 7 ^9 a- [% U. q3 {9 q
项目源码下载:点击下载3 G {; M3 h4 e/ f! f9 g' p
; ]3 B" P: l2 z8 a+ v: U& B$ t |
|