combox constructer problem
im trying to construct a combobox model using a URL and long value... but everytime i compile it i get "cannot resolve symbol - audiofile....... where am i going wrong
public class ComboBoxItem extends JFrame implements ActionListener
{
public ComboBoxItem()
{
Vector model = new Vector();
model.addElement( new AudioInfo("H://sounds//songfiles//spam_song.au", new Long(180* 1000) ));
model.addElement( new AudioInfo("H://sounds//songfiles//spam_song.au", new Long(180* 1000) ));
model.addElement( new AudioInfo("H://sounds//songfiles//spam_song.au", new Long(180* 1000) ));
model.addElement( new AudioInfo("H://sounds//songfiles//spam_song.au", new Long(180* 1000) ));
JComboBox comboBox;
// Easiest approach is to just override toString() method
// of the Item class
comboBox = new JComboBox( model );
comboBox.addActionListener( this );
getContentPane().add(comboBox, BorderLayout.NORTH );
// Most flexible approach is to create a custom render
// to diplay the Item data
}
public void actionPerformed(ActionEvent e)
{
JComboBox comboBox = (JComboBox)e.getSource();
AudioInfo audioinfo = (AudioInfo)comboBox.getSelectedItem();
System.out.println( audioinfo.getlong() + " : " + audioinfo.geturl() );
}
class ItemRenderer extends BasicComboBoxRenderer
{
public Component getListCellRendererComponent(
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus)
{
super.getListCellRendererComponent(list, value, index,
isSelected, cellHasFocus);
if (value != null)
{
AudioInfo audioinfo = (AudiInfo)value;
setText( audioinfo.geturl().toUpperCase() );
}
return this;
}
}
class AudioInfo {
private URL url;
private long time;
/**
* @param url
* @param time
*/
public AudioInfo(URL url, long time) {
this.url = url;
this.time = time;
}
/**
* @return the time
*/
public long getTime() {
return time;
}
/**
* @return the url
*/
public URL getUrl() {
return url;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return url.getFile();
}
}
public static void main(String[] args)
{
JFrame frame = new ComboBoxItem();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible( true );
}
}
Message was edited by:
manicpreacher

