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