Code: Select all
package musicrecord;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
/**
* @version 1.0
* @author Jon C.
*/
public class MusicCollectionUI
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
CheckBoxFrame frame = new CheckBoxFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
/**
* A frame with a sample text label and check boxes for selecting font attributes.
*/
class CheckBoxFrame extends JFrame
{
public CheckBoxFrame()
{
setTitle("CheckBoxTest");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
// add the sample text label
label = new JLabel("The quick brown fox jumps over the lazy dog.");
label.setFont(new Font("Serif", Font.PLAIN, FONTSIZE));
MusicRecord records = new MusicRecord();
ArrayList<String> fields = new ArrayList<String>();
fields.addAll(records.readFields(FILENAME, DELIMITER));
int i = 0;
String[] data = {};
for (String f : fields)
{
data[i] = f;
++i;
}
JList myList = new JList(data);
add(myList, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
add(buttonPanel, BorderLayout.SOUTH);
}
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
private JLabel label;
private JCheckBox bold;
private JCheckBox italic;
private static final int FONTSIZE = 12;
private static String FILENAME = "CATALOG.CSV";
private static String DELIMITER = ",";
}
package musiccollection;
import java.io.*;
import java.util.*;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
/**
*
* @author Jon
* @version 1.0
*/
public class MusicRecord {
public MusicRecord()
{
BasicConfigurator.configure();
}
public String getLocation ()
{
return this.Location;
}
public void setLocation(String location)
{
this.Location = location;
}
public String getTitle()
{
return this.Title;
}
public void setTitle(String title)
{
this.Title = title;
}
public String getAuthor()
{
return this.Author;
}
public void setAuthor (String author)
{
this.Author = author;
}
public String getPublisher()
{
return this.Publisher;
}
public void setPublisher(String publisher)
{
this.Publisher = publisher;
}
public double getPlayTime()
{
return PlayTime;
}
public void setPlayTime (Integer playtime)
{
/* playtime in number of seconds */
this.PlayTime = playtime;
}
public void save(String fileName, String newFileContent) throws IOException
{
StringBuilder addContent = new StringBuilder();
if (existingFileContent != null) addContent.append(existingFileContent);
addContent.append(newFileContent);
BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
out.write(addContent.toString());
out.close();
/* Sourced and adapted from http://zamov.online.fr/EXHTML/JAVA/JAVA_785340.html */
}
public ArrayList<String> readFields (String fileName, String delimiter) throws IOException
{
ArrayList<String> result = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line = null;
while ((line = reader.readLine()) != null)
{
allFields.addAll(Arrays.asList(line.split(delimiter)));
}
reader.close();
whichRecord = 0;
result = allFields;
return result;
}
public ArrayList<String> readNext()
{
ArrayList<String> result = new ArrayList<String>();
if (whichRecord < allFields.size())
{
result.add(allFields.get(++whichRecord));
errorLog.debug(allFields.get(++whichRecord));
return result;
}
else
{
return null;
}
}
public ArrayList<String> readPrevious()
{
ArrayList<String> result = new ArrayList<String>();
if (whichRecord > 0)
{
result.add(allFields.get(--whichRecord));
errorLog.debug(allFields.get(--whichRecord));
return result;
}
else
{
return null;
}
}
public enum MusicType {SOLO, COLLECTION}
public static int whichRecord = 0;
private String Location;
private String Title;
private String Author;
private String Publisher;
private Integer PlayTime;
private String existingFileContent;
private ArrayList<String> allFields = new ArrayList<String>();
private static final Logger errorLog = Logger.getLogger(MusicRecord.class);
}
CATALOG.CSV
A5|Allegro Andante|Beethoven|EMI|0|300|A6|La Marcia Turca|Mozart|EMI|0|300|
Error
C:\Documents and Settings\Jon\Desktop\Nelly\musicrecord\MusicCollectionUI.java:43: cannot find symbol
symbol : class MusicRecord
location: class musicrecord.CheckBoxFrame
MusicRecord records = new MusicRecord();
^
C:\Documents and Settings\Jon\Desktop\Nelly\musicrecord\MusicCollectionUI.java:43: cannot find symbol
symbol : class MusicRecord
location: class musicrecord.CheckBoxFrame
MusicRecord records = new MusicRecord();