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