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