?? source.java
字號(hào):
package MP3;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.*;
import javazoom.jlgui.basicplayer.BasicPlayerEvent;
import WindowType.DragWindowControl;
import Function.Characters;
import Function.ScrollInformation;
import Function.SongString;
import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;
/**
* Created by JFormDesigner on Thu Jul 10 10:22:25 CST 2008 The main class of
* OurMp3 Constructer to set the size ,shape and location of the player And
* create the playlist ,make it unvisible Add MouseListener to the Playlist to
* play the song,when click one of the songs twice successively It can also save
* the song list when you open it again
*
* @see substance.jar
* @author ChenXiaoling
* @author DuXiaojing
*/
public class Source extends JFrame {
public Source() {
this.setUndecorated(true);
initComponents();
//==================改變皮膚==============================
try {
UIManager
.setLookAndFeel("org.jvnet.substance.skin.SubstanceGreenMagicLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
e.printStackTrace();
}
setSize(295, 185);
setLocationRelativeTo(null);// 居中顯示
setVisible(true);
setResizable(false);
playlist = new Playlist();
playlist.setVisible(false);
msize = new MiniSize();
msize.setVisible(false);
windowDragControl.addSubWindow(playlist);
playlist.Playlist.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if (e.getClickCount() == 2) { // ////// //雙擊時(shí)觸發(fā)
dealPlay();
}
}
});
// =============裝載原有列表===========
try {
input = new ObjectInputStream(new FileInputStream("All.dat"));
String name = (String) input.readObject();
rec = new Record();
while (name != null) {
playlist.model.addElement(name);
name = (String) input.readObject();
}
input.close();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (EOFException end) {
try {
input.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Point loc = null;
Point tmp = null;
boolean isDragged = false;
/**
* the method is used to drag the Player window Add MouseListener and
* MouseMotionListener. Use Point object loc and tmp to get the location.
*
* @return void
*/
private void setDragable() {
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent e) {
isDragged = false;
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
public void mousePressed(java.awt.event.MouseEvent e) {
tmp = new Point(e.getX(), e.getY());
isDragged = true;
setCursor(new Cursor(Cursor.MOVE_CURSOR));
}
});
this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent e) {
if (isDragged) {
loc = new Point(getLocation().x + e.getX() - tmp.x,
getLocation().y + e.getY() - tmp.y);
setLocation(loc);
}
}
});
}
/**
* Method to make the JLable object Information start to move .
*
* @see Function.ScrollInformation
*/
//======================= make information scroll in the panel
private void scrollInformation() {
if (scrollInfo != null) {
scrollInfo.setStop(true);
}
scrollInfo = new ScrollInformation(Information, playlist.Playlist
.getSelectedItem());
scrollInfo.start();
if (scrollInfo1 != null) {
scrollInfo1.setStop(true);
}
scrollInfo1 = new ScrollInformation(MInformation, playlist.Playlist
.getSelectedItem());
scrollInfo1.start();
}
/**
* Method to make the JSlider object Progress draggable
*
* @see JSlider
*/
private void ProgressStateChanged() {
// TODO add your code here
if (canDrag) {
if (!Progress.getValueIsAdjusting()) {
if (progressDrag) {
progressDrag = false;
double rate = Progress.getValue() * 1.0
/ Progress.getMaximum();
control.seek(rate);
setVolumn();
}
} else {
progressDrag = true;
}
} else {
Progress.setEnabled(false);
}
}
/**
* Invoked when press the button AddPack Method to add songs to the Playlist
*
* @param e ActionEvent object
*/
private void AddPackActionPerformed(ActionEvent e) {
// TODO add your code here
playlist.addFileToList();
}
/**
* Invoked when press the button Previous Method to get the previous songs
* to the Playlist
*
* @param e ActionEvent object
*/
private void PreviousActionPerformed(ActionEvent e) {
// TODO add your code here
int previousIndex = getPreviousSongIndex();
playlist.Playlist.select(previousIndex);
dealPlay();
}
/**
* Method to get the index of the previous song Judge the playing model
* before that
*
*/
private int getPreviousSongIndex() {
int previousIndex = -1;
int currentindex = getCurrentSelectedIndex();
if (currentindex >= 0) {
boolean isRotate = Rotate.isSelected();
boolean isShuffle = Shuffle.isSelected();
boolean isOrder = Order.isSelected();
boolean isSingle = Single.isSelected();
if (isOrder) {
if (currentindex == 0)
previousIndex = 0;
else
previousIndex = currentindex - 1;
} else if (isRotate) {
if (currentindex == 0)
previousIndex = playlist.Playlist.getItemCount() - 1;
else
previousIndex = currentindex - 1;
}
else if (isShuffle) {
int now = (int) (Math.random() * (playlist.Playlist
.getItemCount())) - 1;
while (getCurrentSelectedIndex() == now)
now = (int) (Math.random() * (playlist.Playlist
.getItemCount())) - 1;
previousIndex = now;
} else if (isSingle)
previousIndex = 0;
else
previousIndex = currentindex;
}
return previousIndex;
}
/**
* Invoked when press the button PausePlay Method to Pause or Play the song
*
* @param e ActionEvent object
*/
private void PausePlayActionPerformed(ActionEvent e) {
// TODO add your code here
PlayPause();
}
private void PlayPause() {
if (playPauseState == Characters.INIT
|| playPauseState == Characters.STOP) {
PausePlay.setText("||");
playPauseState = Characters.PLAY;
playSelectedSong();
} else if (playPauseState == Characters.PLAY
|| playPauseState == Characters.RESUME) {
PausePlay.setText("Play");
playPauseState = Characters.PAUSE;
control.pause();
} else if (playPauseState == Characters.PAUSE) {
PausePlay.setText("||");
playPauseState = Characters.RESUME;
control.resume();
}
}
/**
* Method to play the selected song
*/
private void playSelectedSong() {
// int count=0;
int selectedIndex = getCurrentSelectedIndex();
if (selectedIndex >= 0) {
scrollInformation();
control.stop();
String selectedSong = playlist.Playlist.getItem(selectedIndex);
SongString sv = (SongString) playlist.hashmap.get(selectedSong);
String songPath = sv.getPath();
control.openSong(songPath);
control.play();
setVolumn();
TotalTime.setText(secondToTime((int) control.getTotalTimeSecond()));
canDrag = true;
Progress.setEnabled(true);
}
}
/**
* Method to get the index of the selected song
*
* @return int the index
*/
private int getCurrentSelectedIndex() {
int selectedIndex = playlist.Playlist.getSelectedIndex();
if (selectedIndex < 0) {
if (playlist.Playlist.getItemCount() > 0) {
selectedIndex = 0;
playlist.Playlist.select(selectedIndex);
}
}
return selectedIndex;
}
/**
* make the time display in format"00:00"
*
* @param second the time length of a song
* @return String the time format
*/
String secondToTime(int second) {
DecimalFormat twoDigits = new DecimalFormat("00");
int minutes = (int) Math.floor(second / 60);
int hours = (int) Math.floor(minutes / 60);
minutes = minutes - hours * 60;
second = second - minutes * 60 - hours * 3600;
if (hours == 0)
return twoDigits.format(minutes) + ":" + twoDigits.format(second);
else
return twoDigits.format(hours) + ":" + twoDigits.format(minutes)
+ ":" + twoDigits.format(second);
}
/**
* Invoked when press the button Next Method to play the next song of the
* selected one
*
* @param e ActionEvent object
*/
private void NextActionPerformed(ActionEvent e) {
// TODO add your code here
int nextIndex = getNextSongIndex();
playlist.Playlist.select(nextIndex);
dealPlay();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -