一个晚上了,我还是不明白?各位兄弟,帮帮忙吧!看看下面一段程序是关于JList类的!
rwq_ 2001-07-20 09:54:25 下面这段程序我实现在JLIST类中增加字符串,就是不明白为什么老报错?
(用JB5编写)
package acctrans;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import com.borland.jbcl.layout.*;
import java.io.*;
public class ATMainFrame extends JFrame
{
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
//DefaultListModel model=new DefaultListModel();
//Vector vectorList=new Vector(4,2);
//jList1.setListData(vectorList);
//vectorList.addElement("Onew");
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
DefaultListModel data=new DefaultListModel();
JList jList1 = new JList(data);
data.addElement("one!"); //这里为什么会错?
/**Construct the frame*/
public ATMainFrame()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception
{
//setIconImage(Toolkit.getDefaultToolkit().createImage(ATMainFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(640, 480));
this.setTitle("ATMainFrame");
jButton1.setText("Running");
jButton2.setText("Stop");
jButton3.setText("Exit");
contentPane.add(jButton3, new XYConstraints(390, 227, 120, -1));
contentPane.add(jButton1, new XYConstraints(385, 66, 123, -1));
contentPane.add(jButton2, new XYConstraints(389, 145, 120, -1));
contentPane.add(jList1, new XYConstraints(28, 25, 213, 391));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
}