Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1301154502_lailissaadah_if3912 #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lib/jl1.0.1.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions manifest.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

103 changes: 103 additions & 0 deletions src/task_5/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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;


/**
*
* @author lailis
*/
public class Application {
private ArrayList<String> 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 static class Player {

public Player() {
}

private Player(FileInputStream fis) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

private void play() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

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");
}
}
}
}
73 changes: 73 additions & 0 deletions src/task_5/Controller.java
Original file line number Diff line number Diff line change
@@ -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 lailis
*/
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());
}
}
}
21 changes: 21 additions & 0 deletions src/task_5/Driver.java
Original file line number Diff line number Diff line change
@@ -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 lailis
*/
public class Driver {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Controller c = new Controller();
}

}
163 changes: 163 additions & 0 deletions src/task_5/View.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane2">

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
</Container>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="jScrollPane1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jTextFieldNP" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jButtonAdd" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonDelete" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonPrev" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonPlay" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonStop" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButtonNext" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="118" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jTextFieldNP" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jButtonAdd" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButtonDelete" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButtonPrev" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButtonPlay" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButtonStop" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButtonNext" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="24" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JList" name="jList">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Segoe UI Light" size="12" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Now Playing"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldNP">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButtonAdd">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButtonDelete">
<Properties>
<Property name="text" type="java.lang.String" value="Delete"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButtonPrev">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;&lt;"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButtonPlay">
<Properties>
<Property name="text" type="java.lang.String" value="Play"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButtonStop">
<Properties>
<Property name="text" type="java.lang.String" value="Stop"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButtonNext">
<Properties>
<Property name="text" type="java.lang.String" value="&gt;&gt;"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Segoe UI Light" size="24" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Simple Music Player"/>
</Properties>
</Component>
</SubComponents>
</Form>
Loading