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