Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

trouble with playlist

  Asked By: Diem    Date: Jun 25    Category: Java    Views: 564
  

i am creating a playlist and am having a few problems. my code is
below. it is working ok but i would like to put the code for adding
a file,removing a file, saving etc. in a different class from the
interface class and then just call it from the interface. I have
only tried this with add so far and it is not working for me. the
files won't add to the list. it works fine when i have it all in the
one class! any ideas please.

here is my interface:

import java.awt.*;
import java.awt.event.*;

public class PlayListInterface extends javax.swing.JFrame {

/** Creates new form PlayList */
public PlayListInterface() {
initComponents();
}

FileDialog fd;
List lstPlayList;


/** 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.
*/
private void initComponents() {
Options = new javax.swing.JPanel();
Add = new javax.swing.JButton();
Remove = new javax.swing.JButton();
Open = new javax.swing.JButton();
Save = new javax.swing.JButton();
New = new javax.swing.JButton();
ToolBar = new javax.swing.JPanel();
Title = new javax.swing.JLabel();
Artist = new javax.swing.JLabel();
Album = new javax.swing.JLabel();
Genre = new javax.swing.JLabel();
main = new javax.swing.JPanel();

getContentPane().setLayout(null);

setTitle("PlayList");
setMaximizedBounds(new java.awt.Rectangle(0, 0, 409, 500));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt)
{
formWindowClosed(evt);
}
});

Options.setLayout(null);

Options.setBorder(new javax.swing.border.MatteBorder(null));
Add.setBackground(new java.awt.Color(51, 204, 255));
Add.setText("Add");
Add.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
addFile(evt);
}
});

Options.add(Add);
Add.setBounds(10, 15, 90, 25);

Remove.setBackground(new java.awt.Color(51, 204, 255));
Remove.setText("Remove");
Remove.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
removeFile(evt);
}
});

Options.add(Remove);
Remove.setBounds(10, 50, 90, 25);

Open.setBackground(new java.awt.Color(51, 204, 255));
Open.setText("Open");
Open.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
openList(evt);
}
});

Options.add(Open);
Open.setBounds(110, 15, 90, 25);

Save.setBackground(new java.awt.Color(51, 204, 255));
Save.setText("Save");
Save.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
saveList(evt);
}
});

Options.add(Save);
Save.setBounds(110, 50, 90, 25);

New.setBackground(new java.awt.Color(51, 204, 255));
New.setText("New");
New.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
newList(evt);
}
});

Options.add(New);
New.setBounds(210, 15, 90, 25);

getContentPane().add(Options);
Options.setBounds(0, 365, 400, 100);

ToolBar.setLayout(null);

ToolBar.setBorder(new javax.swing.border.LineBorder(new
java.awt.Color(0, 0, 0)));
Title.setText("Title");
ToolBar.add(Title);
Title.setBounds(10, 7, 120, 16);

Artist.setText("Artist");
ToolBar.add(Artist);
Artist.setBounds(130, 7, 100, 16);

Album.setText("Album");
ToolBar.add(Album);
Album.setBounds(230, 7, 80, 16);

Genre.setText("Genre");
ToolBar.add(Genre);
Genre.setBounds(310, 7, 80, 16);

getContentPane().add(ToolBar);
ToolBar.setBounds(0, 0, 400, 30);

main.setLayout(null);

lstPlayList = new List();
main.add(lstPlayList);
lstPlayList.setBounds(0, 0, 400, 336);

getContentPane().add(main);
main.setBounds(0, 30, 400, 336);

pack();
}

private void formWindowClosed(java.awt.event.WindowEvent evt) {
// Add your handling code here:
}

private void saveList(java.awt.event.MouseEvent evt) {
System.out.println("List has been saved");
}

private void removeFile(java.awt.event.MouseEvent evt) {
System.out.println("File has been removed");
}

private void newList(java.awt.event.MouseEvent evt) {
System.out.println("New List has been created");
}

private void openList(java.awt.event.MouseEvent evt) {
System.out.println("List Opened");
}

PlayListDriver pld;

private void addFile(java.awt.event.MouseEvent evt) {
fd = new FileDialog(this);

fd.show();

pld = new PlayListDriver();

pld.Add();

}

/** Exit the Application */



/**
* @param args the command line arguments
*/
public static void main(String args[]) {

new PlayListInterface().show();
}


// Variables declaration - do not modify
public javax.swing.JButton Add;
public javax.swing.JLabel Album;
public javax.swing.JLabel Artist;
public javax.swing.JLabel Genre;
public javax.swing.JButton New;
public javax.swing.JButton Open;
public javax.swing.JPanel Options;
public javax.swing.JButton Remove;
public javax.swing.JButton Save;
public javax.swing.JLabel Title;
public javax.swing.JPanel ToolBar;
public javax.swing.JPanel main;

// End of variables declaration

}
and here is the other class:

public class PlayListFunctions
{
PlayListInterface pli = new PlayListInterface();

FileDialog fd = new FileDialog(new PlayListInterface());;

public void Add()
{

if (fd.getDirectory() != null &&fd.getFile() != null)
{
pli.lstPlayList.add(fd.getDirectory() + fd.getFile
());

}
}

}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on trouble with playlist Or get search suggestion and latest updates.




Tagged: