步骤1
绑定的代码的特定事件,使用addActionListener
方法。
button.addActionListener(new ActionListener({
public void actionPerformed(ActionEvent e)
{
// Bind the method to the button.
}
});
步骤2
填充与相关代码的方法。
String value = jTextBox.getText();
// Grab the String value.
jListModel.addElement(value);
// And add it to the list model that informs the JList.
共
button.addActionListener(new ActionListener({
public void actionPerformed(ActionEvent e)
{
String value = jTextBox.getText();
// Grab the String value.
jListModel.addElement(value);
// And add it to the list.
}
});
有用的链接
Here是Oracle一个非常好的教程,详细说明了如何操纵列表一百万和一个不同的方式。
我试图重新键入docs.oracle.com的一些代码,但我无法真正理解那里的公共,类和许多事情。我已经阅读了教程,并得到了什么字符串,整数的意思,如何声明它们,这几乎是。我在netbeans中做了我的GUI模型,但是我还没有足够的声望发布图像。 – user2629807