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