我遇见了一个循环问题,问题在于如下一段代码:
for(int i=0;i<=templefile_list.length;i++)
           name[i]= templefile_list[i].getName();
导致Applet小程序出现“未初始化小程序”,如不使用for循环则不会出现以上问题,但是处了循环我也不知道如何对
name[]进行赋值,请高手指点一下。原代码如下:
public class J_Ketoo extends JApplet implements ActionListener,ItemListener
{ File f = new File("D:\\Enterprise-SDK-Callisto-322-win32\\workspace\\J_Audio\\Audio");
File[] templefile_list=f.listFiles();//templefile_list数据中包含目录下所有文件及目录
String name[] = new String[templefile_list.length];

private AudioClip  m_soundCurrent;
private AudioClip[] m_sound= new AudioClip[templefile_list.length];
private JButton m_buttonPlay, m_buttonLoop, m_buttonStop;
private JComboBox myList;


public void init()
{
Container container = getContentPane();
container.setLayout(new FlowLayout());
/*
name[0]= templefile_list[0].getName();
*/
for(int i=0;i<=templefile_list.length;i++)
        name[i]= templefile_list[i].getName();

myList =new JComboBox(name);
myList.addItemListener( this );
container.add( myList);

m_buttonPlay = new JButton("Play");
m_buttonPlay.addActionListener( this );
container.add( m_buttonPlay );

m_buttonLoop = new JButton("Loop");
m_buttonLoop.addActionListener( this );
container.add( m_buttonLoop );

m_buttonStop = new JButton("Stop");
m_buttonStop.addActionListener( this );
container.add( m_buttonStop );


m_sound[0] = getAudioClip( getDocumentBase(),name[0]);


for(int i=0;i<=templefile_list.length;i++)
{ /*
m_sound[i] = getAudioClip( getDocumentBase(),name[i]);
*/
}
m_soundCurrent = m_sound[0];


}

public void stop()//Stop playing sound
{
m_soundCurrent.stop();
}

public void itemStateChanged(ItemEvent e) 
{
/*
m_soundCurrent.stop();
m_soundCurrent =(myList.getSelectedIndex()==0? m_soundFirst : m_soundSecond);
*/
}
public void actionPerformed(ActionEvent e) 
{
/*
if( e.getSource()== m_buttonPlay )
m_soundCurrent.play();
else if( e.getSource() == m_buttonStop)
m_soundCurrent.stop();
else if( e.getSource() == m_buttonLoop)
m_soundCurrent.loop();
*/
} }