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