diff --git a/Task_5/lib/jl1.0.1.jar b/Task_5/lib/jl1.0.1.jar new file mode 100644 index 0000000..bd5fb8b Binary files /dev/null and b/Task_5/lib/jl1.0.1.jar differ diff --git a/Task_5/manifest.mf b/Task_5/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Task_5/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Task_5/nbproject/build-impl.xml b/Task_5/nbproject/build-impl.xml new file mode 100644 index 0000000..64a8231 --- /dev/null +++ b/Task_5/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Task_5/nbproject/genfiles.properties b/Task_5/nbproject/genfiles.properties new file mode 100644 index 0000000..4f18471 --- /dev/null +++ b/Task_5/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=652a6206 +build.xml.script.CRC32=2cc291bd +build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=652a6206 +nbproject/build-impl.xml.script.CRC32=c46ee1f5 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/Task_5/nbproject/private/private.properties b/Task_5/nbproject/private/private.properties new file mode 100644 index 0000000..df5629b --- /dev/null +++ b/Task_5/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/Task_5/nbproject/private/private.xml b/Task_5/nbproject/private/private.xml new file mode 100644 index 0000000..d6ff055 --- /dev/null +++ b/Task_5/nbproject/private/private.xml @@ -0,0 +1,12 @@ + + + + + + file:/F:/Task_5/Task_5/src/task_5/View.java + file:/F:/Task_5/Task_5/src/task_5/Driver.java + file:/F:/Task_5/Task_5/src/task_5/Application.java + file:/F:/Task_5/Task_5/src/task_5/Controller.java + + + diff --git a/Task_5/nbproject/project.properties b/Task_5/nbproject/project.properties new file mode 100644 index 0000000..01a3bf2 --- /dev/null +++ b/Task_5/nbproject/project.properties @@ -0,0 +1,76 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Task_5.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.jl1.0.1.jar=D:\\temp\\JLayer1.0.1\\jl1.0.1.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.jl1.0.1.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=task_5.Driver +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Task_5/nbproject/project.xml b/Task_5/nbproject/project.xml new file mode 100644 index 0000000..53c05f0 --- /dev/null +++ b/Task_5/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Task_5 + + + + + + + + + diff --git a/Task_5/src/task_5/Application.java b/Task_5/src/task_5/Application.java new file mode 100644 index 0000000..0b1f6fa --- /dev/null +++ b/Task_5/src/task_5/Application.java @@ -0,0 +1,92 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package task_5; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import javazoom.jl.decoder.JavaLayerException; +import javazoom.jl.player.Player; + +/** + * + * @author cleanrun + */ +public class Application { + private ArrayList musicList; + private ThreadPlayer thread; + private int nowPlaying; + + + public Application(){ + musicList = new ArrayList<>(); + } + + public void addMusic(String path){ + musicList.add(path); + } + + public String[] getMusicList(){ + return (String[]) musicList.toArray(new String[0]); + } + + public String getNowPlayed(){ + return musicList.get(nowPlaying); + } + + public void removeMusic(int i){ + musicList.remove(i); + } + + public void play(int i){ + nowPlaying = i; + String filepath = musicList.get(i); + thread = new ThreadPlayer(filepath); + thread.start(); + } + + public void stop(){ + if(thread != null){ + thread.stop(); + } + } + + public void next(){ + if(nowPlaying < musicList.size() - 1){ + stop(); + play(nowPlaying + 1); + } + } + + public void prev(){ + if(nowPlaying != 0){ + stop(); + play(nowPlaying - 1); + } + } + + private class ThreadPlayer extends Thread{ + private String filepath; + private Player player; + + public ThreadPlayer(String filepath){ + this.filepath = filepath; + } + + @Override + public void run(){ + try{ + FileInputStream fis = new FileInputStream(filepath); + player = new Player(fis); + player.play(); + }catch(FileNotFoundException e){ + throw new IllegalStateException("File " + filepath + " not found"); + }catch(JavaLayerException e){ + throw new IllegalStateException("Error while playing file"); + } + } + } +} diff --git a/Task_5/src/task_5/Controller.java b/Task_5/src/task_5/Controller.java new file mode 100644 index 0000000..5d3e475 --- /dev/null +++ b/Task_5/src/task_5/Controller.java @@ -0,0 +1,73 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package task_5; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JOptionPane; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileNameExtensionFilter; +/** + * + * @author cleanrun + */ +public class Controller implements ActionListener{ + private Application model; + private View view; + + public Controller(){ + model = new Application(); + view = new View(); + view.setVisible(true); + view.addActionListener(this); + view.setListMusic(model.getMusicList()); + } + + @Override + public void actionPerformed(ActionEvent ae) { + Object click = ae.getSource(); + + try{ + if(click.equals(view.getButtonAdd())){ + JFileChooser fc = new JFileChooser(); + FileNameExtensionFilter filter = new FileNameExtensionFilter("mp3 Files", "mp3", "mp3"); + fc.setFileFilter(filter); + int returnVal = fc.showOpenDialog(view); + + if(returnVal == JFileChooser.APPROVE_OPTION){ + String path = fc.getSelectedFile().getAbsolutePath(); + model.addMusic(path); + view.setListMusic(model.getMusicList()); + } + } + else if(click.equals(view.getButtonDelete())){ + int selected = view.getSelectedMusic(); + model.removeMusic(selected); + view.setListMusic(model.getMusicList()); + } + else if(click.equals(view.getButtonNext())){ + model.next(); + view.setFieldPlaying(model.getNowPlayed()); + } + else if(click.equals(view.getButtonPlay())){ + int selected = view.getSelectedMusic(); + model.stop(); + model.play(selected); + view.setFieldPlaying(model.getNowPlayed()); + } + else if(click.equals(view.getButtonPrev())){ + model.prev(); + view.setFieldPlaying(model.getNowPlayed()); + } + else if(click.equals(view.getButtonStop())){ + model.stop(); + view.setFieldPlaying(""); + } + }catch(Exception e){ + JOptionPane.showMessageDialog(view, e.getMessage()); + } + } +} diff --git a/Task_5/src/task_5/Driver.java b/Task_5/src/task_5/Driver.java new file mode 100644 index 0000000..34a7444 --- /dev/null +++ b/Task_5/src/task_5/Driver.java @@ -0,0 +1,21 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package task_5; + +/** + * + * @author cleanrun + */ +public class Driver { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Controller c = new Controller(); + } + +} diff --git a/Task_5/src/task_5/View.form b/Task_5/src/task_5/View.form new file mode 100644 index 0000000..6c01e88 --- /dev/null +++ b/Task_5/src/task_5/View.form @@ -0,0 +1,157 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Task_5/src/task_5/View.java b/Task_5/src/task_5/View.java new file mode 100644 index 0000000..e10d7b8 --- /dev/null +++ b/Task_5/src/task_5/View.java @@ -0,0 +1,225 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package task_5; + +import java.awt.event.ActionListener; +import javax.swing.JButton; + +/** + * + * @author cleanrun + */ +public class View extends javax.swing.JFrame { + + /** + * Creates new form View + */ + public View() { + initComponents(); + setLocationRelativeTo(null); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jList = new javax.swing.JList<>(); + jLabel1 = new javax.swing.JLabel(); + jTextFieldNP = new javax.swing.JTextField(); + jButtonAdd = new javax.swing.JButton(); + jButtonDelete = new javax.swing.JButton(); + jButtonPrev = new javax.swing.JButton(); + jButtonPlay = new javax.swing.JButton(); + jButtonStop = new javax.swing.JButton(); + jButtonNext = new javax.swing.JButton(); + jLabel2 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setResizable(false); + + jScrollPane1.setViewportView(jList); + + jLabel1.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N + jLabel1.setText("Now Playing"); + + jTextFieldNP.setEditable(false); + + jButtonAdd.setText("Add"); + + jButtonDelete.setText("Delete"); + + jButtonPrev.setText("<<"); + + jButtonPlay.setText("Play"); + + jButtonStop.setText("Stop"); + + jButtonNext.setText(">>"); + + jLabel2.setFont(new java.awt.Font("Segoe UI Light", 0, 24)); // NOI18N + jLabel2.setText("Simple Music Player"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel2) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jScrollPane1) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jTextFieldNP)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(jButtonAdd) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButtonDelete) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButtonPrev) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButtonPlay) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButtonStop) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButtonNext))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(jTextFieldNP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButtonAdd) + .addComponent(jButtonDelete) + .addComponent(jButtonPrev) + .addComponent(jButtonPlay) + .addComponent(jButtonStop) + .addComponent(jButtonNext)) + .addContainerGap(24, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(View.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(View.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(View.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(View.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new View().setVisible(true); + } + }); + } + + public void addActionListener(ActionListener a){ + jButtonAdd.addActionListener(a); + jButtonDelete.addActionListener(a); + jButtonNext.addActionListener(a); + jButtonPlay.addActionListener(a); + jButtonPrev.addActionListener(a); + jButtonStop.addActionListener(a); + } + + public JButton getButtonAdd(){ + return jButtonAdd; + } + + public JButton getButtonDelete(){ + return jButtonDelete; + } + + public JButton getButtonNext(){ + return jButtonNext; + } + + public JButton getButtonPlay(){ + return jButtonPlay; + } + + public JButton getButtonPrev(){ + return jButtonPrev; + } + + public JButton getButtonStop(){ + return jButtonStop; + } + + public void setListMusic(String[] musicList){ + jList.setListData(musicList); + } + + public void setFieldPlaying(String filename){ + jTextFieldNP.setText(filename); + } + + public int getSelectedMusic(){ + if(jList.getSelectedIndex() == -1){ + throw new IllegalStateException("Please select any music"); + } + return jList.getSelectedIndex(); + } + + + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButtonAdd; + private javax.swing.JButton jButtonDelete; + private javax.swing.JButton jButtonNext; + private javax.swing.JButton jButtonPlay; + private javax.swing.JButton jButtonPrev; + private javax.swing.JButton jButtonStop; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JList jList; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextField jTextFieldNP; + // End of variables declaration//GEN-END:variables +} diff --git a/asset/Thumbs.db b/asset/Thumbs.db new file mode 100644 index 0000000..cb2d136 Binary files /dev/null and b/asset/Thumbs.db differ