JavaでKugouからダウンロードした音楽をアレンジ
3073 ワード
音楽管理:
import java.io.File;
/**
*
* @author tntxia
*
*/
public class MusicManager {
/**
*
* @param kugouPath
* @param musicPath
*/
public static void transMusic(String kugouPath,String musicPath){
File kugouPathFile = new File(kugouPath);
// Kugou
for(File f : kugouPathFile.listFiles()){
if(f.isFile()){
String fileName = f.getName(); //
String singer = fileName.split("-")[0].trim(); //
File file = new File(musicPath+"\\"+singer); //
if(!file.exists()) // ,
file.mkdir();
f.renameTo(new File(musicPath+"\\"+singer+"\\"+fileName)); //
}
}
}
}
パブリックウィンドウクラス
import java.awt.Container;
import java.util.Map;
import javax.swing.JFrame;
/**
*
* Swing
* @author tntxia
*
*/
public class CommonFrame extends JFrame{
private Container content = null;
public CommonFrame(){
this.content = this.getContentPane();
//
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Container getContent() {
return content;
}
public void setContent(Container content) {
this.content = content;
}
}
音楽管理ウィンドウクラス
import java.awt.*;
import java.awt.event.*;
import java.util.ResourceBundle;
import javax.swing.*;
/**
*
* @author tntxia
*
*/
public class MusicFrame extends CommonFrame{
private JLabel label = new JLabel("Kugou :");
private JTextField text = new JTextField(20);
private JLabel label2 = new JLabel(" :");
private JTextField text2 = new JTextField(20);
private JButton button = new JButton(" ");
public MusicFrame(){
ResourceBundle rs = ResourceBundle.getBundle("music");
Container content = this.getContent();
content.setLayout(new FlowLayout());
content.add(label);
text.setText(rs.getString("kugouPath"));
content.add(text);
content.add(label2);
text2.setText(rs.getString("musicPath"));
content.add(text2);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
MusicManager.transMusic(text.getText(), text2.getText());
}
});
content.add(button);
this.pack();
this.setVisible(true);
}
public static void main(String[] args){
new MusicFrame();
}
}